summaryrefslogtreecommitdiff
path: root/gnu/build/linux-container.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/build/linux-container.scm')
-rw-r--r--gnu/build/linux-container.scm20
1 files changed, 14 insertions, 6 deletions
diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm
index bdeca2cdb9f..03c01439cea 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."
303 303
304(define* (call-with-container mounts thunk #:key (namespaces %namespaces) 304(define* (call-with-container mounts thunk #:key (namespaces %namespaces)
305 (host-uids 1) (guest-uid 0) (guest-gid 0) 305 (host-uids 1) (guest-uid 0) (guest-gid 0)
306 (relayed-signals (list SIGINT SIGTERM))
306 (process-spawned-hook (const #t))) 307 (process-spawned-hook (const #t)))
307 "Run THUNK in a new container process and return its exit status; call 308 "Run THUNK in a new container process and return its exit status; call
308PROCESS-SPAWNED-HOOK with the PID of the new process that has been spawned. 309PROCESS-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.
320GUEST-UID and GUEST-GID specify the first UID (respectively GID) that host 321GUEST-UID and GUEST-GID specify the first UID (respectively GID) that host
321UIDs (respectively GIDs) map to in the namespace. 322UIDs (respectively GIDs) map to in the namespace.
322 323
324RELAYED-SIGNALS is the list of signals that are \"relayed\" to the container
325process when caught by its parent.
326
323Note that if THUNK needs to load any additional Guile modules, the relevant 327Note that if THUNK needs to load any additional Guile modules, the relevant
324module files must be present in one of the mappings in MOUNTS and the Guile 328module files must be present in one of the mappings in MOUNTS and the Guile
325load path must be adjusted as needed." 329load path must be adjusted as needed."
330 (define (install-signal-handlers pid)
331 ;; Install handlers that forward signals to PID.
332 (define (relay-signal signal)
333 (false-if-exception (kill pid signal)))
334
335 (for-each (lambda (signal)
336 (sigaction signal relay-signal))
337 relayed-signals))
338
326 (call-with-temporary-directory 339 (call-with-temporary-directory
327 (lambda (root) 340 (lambda (root)
328 (let ((pid (run-container root mounts namespaces host-uids thunk 341 (let ((pid (run-container root mounts namespaces host-uids thunk
329 #:guest-uid guest-uid 342 #:guest-uid guest-uid
330 #:guest-gid guest-gid))) 343 #:guest-gid guest-gid)))
331 ;; Catch SIGINT and kill the container process. 344 (install-signal-handlers pid)
332 (sigaction SIGINT
333 (lambda (signum)
334 (false-if-exception
335 (kill pid SIGKILL))))
336
337 (process-spawned-hook pid) 345 (process-spawned-hook pid)
338 (match (waitpid pid) 346 (match (waitpid pid)
339 ((_ . status) status)))))) 347 ((_ . status) status))))))