gnu: python-pkginfo: Update to 1.4.2.
[jackhill/guix/guix.git] / gnu / build / linux-container.scm
index dd56a79..65e1325 100644 (file)
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
+;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -32,7 +33,8 @@
             %namespaces
             run-container
             call-with-container
-            container-excursion))
+            container-excursion
+            container-excursion*))
 
 (define (user-namespace-supported?)
   "Return #t if user namespaces are supported on this system."
@@ -59,9 +61,14 @@ exists."
     (const #t)
     (lambda ()
       (thunk)
-      (primitive-exit 0))
+
+      ;; XXX: Somehow we sometimes get EBADF from write(2) or close(2) upon
+      ;; exit (coming from fd finalizers) when used by the Shepherd.  To work
+      ;; around that, exit forcefully so fd finalizers don't have a chance to
+      ;; run and fail.
+      (primitive-_exit 0))
     (lambda ()
-      (primitive-exit 1))))
+      (primitive-_exit 1))))
 
 (define (purify-environment)
   "Unset all environment variables."
@@ -150,8 +157,7 @@ for the process."
 
   ;; Mount user-specified file systems.
   (for-each (lambda (file-system)
-              (mount-file-system (file-system->spec file-system)
-                                 #:root root))
+              (mount-file-system file-system #:root root))
             mounts)
 
   ;; Jail the process inside the container's root file system.
@@ -326,3 +332,22 @@ return the exit status."
      (match (waitpid pid)
        ((_ . status)
         (status:exit-val status))))))
+
+(define (container-excursion* pid thunk)
+  "Like 'container-excursion', but return the return value of THUNK."
+  (match (pipe)
+    ((in . out)
+     (match (container-excursion pid
+              (lambda ()
+                (close-port in)
+                (write (thunk) out)
+                (close-port out)))
+       (0
+        (close-port out)
+        (let ((result (read in)))
+          (close-port in)
+          result))
+       (_                                         ;maybe PID died already
+        (close-port out)
+        (close-port in)
+        #f)))))