diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2017-02-06 23:45:00 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2017-02-07 00:08:10 +0100 |
| commit | c90db25f4cf1f98f3f4f3af38d175a14ffb8c32a (patch) | |
| tree | f419dee5d3df1f967312db49d373b44a49e93d48 /gnu/build/linux-container.scm | |
| parent | b9a5efa59673dc9061714a9b0b15b43696bfd38c (diff) | |
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/build/linux-container.scm')
| -rw-r--r-- | gnu/build/linux-container.scm | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm index dd56a792320..95bfd92ddef 100644 --- a/gnu/build/linux-container.scm +++ b/gnu/build/linux-container.scm | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> | 2 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> |
| 3 | ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | ;;; | 4 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 6 | ;;; |
| @@ -32,7 +33,8 @@ | |||
| 32 | %namespaces | 33 | %namespaces |
| 33 | run-container | 34 | run-container |
| 34 | call-with-container | 35 | call-with-container |
| 35 | container-excursion)) | 36 | container-excursion |
| 37 | container-excursion*)) | ||
| 36 | 38 | ||
| 37 | (define (user-namespace-supported?) | 39 | (define (user-namespace-supported?) |
| 38 | "Return #t if user namespaces are supported on this system." | 40 | "Return #t if user namespaces are supported on this system." |
| @@ -326,3 +328,21 @@ return the exit status." | |||
| 326 | (match (waitpid pid) | 328 | (match (waitpid pid) |
| 327 | ((_ . status) | 329 | ((_ . status) |
| 328 | (status:exit-val status)))))) | 330 | (status:exit-val status)))))) |
| 331 | |||
| 332 | (define (container-excursion* pid thunk) | ||
| 333 | "Like 'container-excursion', but return the return value of THUNK." | ||
| 334 | (match (pipe) | ||
| 335 | ((in . out) | ||
| 336 | (match (container-excursion pid | ||
| 337 | (lambda () | ||
| 338 | (close-port in) | ||
| 339 | (write (thunk) out))) | ||
| 340 | (0 | ||
| 341 | (close-port out) | ||
| 342 | (let ((result (read in))) | ||
| 343 | (close-port in) | ||
| 344 | result)) | ||
| 345 | (_ ;maybe PID died already | ||
| 346 | (close-port out) | ||
| 347 | (close-port in) | ||
| 348 | #f))))) | ||
