diff options
author | Ludovic Courtès <ludo@gnu.org> | 2022-04-16 19:26:11 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-05-01 21:30:34 +0200 |
commit | a76fa226c8761dd349aaacca7ba041429bce4e73 (patch) | |
tree | 80f2d7a2017e8234267fbea1ce48ec5ba647bab2 /gnu/build | |
parent | eaebc7f2b715093baf0d4a8c86d7e1a6af20ebc8 (diff) | |
download | guix-a76fa226c8761dd349aaacca7ba041429bce4e73.tar.gz |
linux-container: 'call-with-container' relays SIGTERM and SIGINT.
* gnu/build/linux-container.scm (call-with-container): Add #:relayed-signals. [install-signal-handlers]: New procedure. Call it.
Diffstat (limited to 'gnu/build')
-rw-r--r-- | gnu/build/linux-container.scm | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm index bdeca2cdb9..03c01439ce 100644 --- a/gnu/build/linux-container.scm +++ b/gnu/build/linux-container.scm @@ -303,6 +303,7 @@ delete it when leaving the dynamic extent of this call." (define* (call-with-container mounts thunk #:key (namespaces %namespaces) (host-uids 1) (guest-uid 0) (guest-gid 0) + (relayed-signals (list SIGINT SIGTERM)) (process-spawned-hook (const #t))) "Run THUNK in a new container process and return its exit status; call PROCESS-SPAWNED-HOOK with the PID of the new process that has been spawned. @@ -320,20 +321,27 @@ can map more than a single uid/gid. GUEST-UID and GUEST-GID specify the first UID (respectively GID) that host UIDs (respectively GIDs) map to in the namespace. +RELAYED-SIGNALS is the list of signals that are \"relayed\" to the container +process when caught by its parent. + Note that if THUNK needs to load any additional Guile modules, the relevant module files must be present in one of the mappings in MOUNTS and the Guile load path must be adjusted as needed." + (define (install-signal-handlers pid) + ;; Install handlers that forward signals to PID. + (define (relay-signal signal) + (false-if-exception (kill pid signal))) + + (for-each (lambda (signal) + (sigaction signal relay-signal)) + relayed-signals)) + (call-with-temporary-directory (lambda (root) (let ((pid (run-container root mounts namespaces host-uids thunk #:guest-uid guest-uid #:guest-gid guest-gid))) - ;; Catch SIGINT and kill the container process. - (sigaction SIGINT - (lambda (signum) - (false-if-exception - (kill pid SIGKILL)))) - + (install-signal-handlers pid) (process-spawned-hook pid) (match (waitpid pid) ((_ . status) status)))))) |