aboutsummaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-02-06 23:45:00 +0100
committerLudovic Courtès <ludo@gnu.org>2017-02-07 00:08:10 +0100
commitc90db25f4cf1f98f3f4f3af38d175a14ffb8c32a (patch)
treef419dee5d3df1f967312db49d373b44a49e93d48 /gnu
parentb9a5efa59673dc9061714a9b0b15b43696bfd38c (diff)
downloadguix-c90db25f4cf1f98f3f4f3af38d175a14ffb8c32a.tar
guix-c90db25f4cf1f98f3f4f3af38d175a14ffb8c32a.tar.gz
linux-container: Add 'container-excursion*'.
* gnu/build/linux-container.scm (container-excursion*): New procedure. * tests/containers.scm ("container-excursion*") ("container-excursion*, same namespaces"): New tests.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/build/linux-container.scm22
1 files changed, 21 insertions, 1 deletions
diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm
index dd56a79232..95bfd92dde 100644
--- a/gnu/build/linux-container.scm
+++ b/gnu/build/linux-container.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015 David Thompson <davet@gnu.org>
+;;; Copyright © 2017 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."
@@ -326,3 +328,21 @@ 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)))
+ (0
+ (close-port out)
+ (let ((result (read in)))
+ (close-port in)
+ result))
+ (_ ;maybe PID died already
+ (close-port out)
+ (close-port in)
+ #f)))))