[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
04/09: linux-container: new use-output argument.
From: |
guix-commits |
Subject: |
04/09: linux-container: new use-output argument. |
Date: |
Sat, 2 Feb 2019 14:10:30 -0500 (EST) |
reepca pushed a commit to branch guile-daemon
in repository guix.
commit 1a17c6bae6772c41f63aceeafdb90f78defda2cc
Author: Caleb Ristvedt <address@hidden>
Date: Mon Aug 28 23:44:23 2017 -0500
linux-container: new use-output argument.
* gnu/build/linux-container.scm:
(call-with-container): new use-output argument, attempts to unmount
container root when it exits.
(run-container): container root directory is now visible outside of
container, but anything mounted under it is not. User namespace option
is in a broken state now, needs further investigation.
(try-umount): new procedure.
---
gnu/build/linux-container.scm | 54 +++++++++++++++++++++++++++++--------------
1 file changed, 37 insertions(+), 17 deletions(-)
diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm
index 65e1325..b01f2de 100644
--- a/gnu/build/linux-container.scm
+++ b/gnu/build/linux-container.scm
@@ -100,7 +100,9 @@ for the process."
;; The container's file system is completely ephemeral, sans directories
;; bind-mounted from the host.
- (mount "none" root "tmpfs")
+ ;; Make this private in the container namespace so everything mounted under
+ ;; it is local to this namespace.
+ (mount "none" root "none" MS_PRIVATE)
;; A proc mount requires a new pid namespace.
(when mount-/proc?
@@ -215,8 +217,12 @@ corresponds to the symbols in NAMESPACES."
the root directory for the container. MOUNTS is a list of <file-system>
objects that specify file systems to mount inside the container. NAMESPACES
is a list of symbols that correspond to the possible Linux namespaces: mnt,
-ipc, uts, user, and net. HOST-UIDS specifies the number of
-host user identifiers to map into the user namespace."
+ipc, uts, user, and net. HOST-UIDS specifies the number of host user
+identifiers to map into the user namespace."
+ ;; this needs to be visible outside the namespace if anyone wants to use the
+ ;; file-system output of running THUNK.
+ (when (memq 'mnt namespaces)
+ (mount "none" root "tmpfs"))
;; The parent process must initialize the user namespace for the child
;; before it can boot. To negotiate this, a pipe is used such that the
;; child process blocks until the parent writes to it.
@@ -249,7 +255,7 @@ host user identifiers to map into the user namespace."
(write 'ready child)
(close-port child)
(thunk))
- (_ ;parent died or something
+ (_ ;parent died or something
(primitive-exit 2))))))
(pid
(close-port child)
@@ -263,15 +269,21 @@ host user identifiers to map into the user namespace."
(let ((message (read parent)))
(close-port parent)
(match message
- ('ready ;success
+ ('ready ;success
pid)
- (((? symbol? key) args ...) ;exception
+ (((? symbol? key) args ...) ;exception
(apply throw key args))
- (_ ;unexpected termination
+ (_ ;unexpected termination
#f)))))))))
+(define (try-umount maybe-mountpoint)
+ (catch #t
+ (lambda ()
+ (umount maybe-mountpoint))
+ noop))
+
(define* (call-with-container mounts thunk #:key (namespaces %namespaces)
- (host-uids 1))
+ (host-uids 1) use-output)
"Run THUNK in a new container process and return its exit status.
MOUNTS is a list of <file-system> objects that specify file systems to mount
inside the container. NAMESPACES is a list of symbols corresponding to
@@ -287,15 +299,23 @@ module files must be present in one of the mappings in
MOUNTS and the Guile
load path must be adjusted as needed."
(call-with-temporary-directory
(lambda (root)
- (let ((pid (run-container root mounts namespaces host-uids thunk)))
- ;; Catch SIGINT and kill the container process.
- (sigaction SIGINT
- (lambda (signum)
- (false-if-exception
- (kill pid SIGKILL))))
-
- (match (waitpid pid)
- ((_ . status) status))))))
+ (dynamic-wind
+ (const #t)
+ (lambda ()
+ (let ((pid (run-container root mounts namespaces host-uids thunk)))
+ ;; Catch SIGINT and kill the container process.
+ (sigaction SIGINT
+ (lambda (signum)
+ (false-if-exception
+ (kill pid SIGKILL))))
+
+ (match (waitpid pid)
+ ((_ . status)
+ (when use-output
+ (use-output root))
+ status))))
+ (lambda ()
+ (try-umount root))))))
(define (container-excursion pid thunk)
"Run THUNK as a child process within the namespaces of process PID and
- branch guile-daemon created (now c1b79c5), guix-commits, 2019/02/02
- 02/09: guix: store: Make register-items transactional, register drv outputs, guix-commits, 2019/02/02
- 01/09: patches: honor NIX_STORE in site.py., guix-commits, 2019/02/02
- 05/09: build-derivations: use call-with-container, guix-commits, 2019/02/02
- 04/09: linux-container: new use-output argument.,
guix-commits <=
- 09/09: gnu: linux-container: Make it more suitable for derivation-building., guix-commits, 2019/02/02
- 06/09: build-derivations: initial build-group support, guix-commits, 2019/02/02
- 08/09: build-derivations: Leaked environment variables more robust., guix-commits, 2019/02/02
- 03/09: guix/store/build-derivations.scm: new module., guix-commits, 2019/02/02
- 07/09: linux-container: don't include /dev/ptmx or /dev/pts from host., guix-commits, 2019/02/02