[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
07/09: linux-container: Add 'container-excursion*'.
From: |
Ludovic Courtès |
Subject: |
07/09: linux-container: Add 'container-excursion*'. |
Date: |
Mon, 6 Feb 2017 23:08:27 +0000 (UTC) |
civodul pushed a commit to branch master
in repository guix.
commit c90db25f4cf1f98f3f4f3af38d175a14ffb8c32a
Author: Ludovic Courtès <address@hidden>
Date: Mon Feb 6 23:45:00 2017 +0100
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.
---
gnu/build/linux-container.scm | 22 +++++++++++++++++++++-
tests/containers.scm | 27 +++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm
index dd56a79..95bfd92 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 <address@hidden>
+;;; Copyright © 2017 Ludovic Courtès <address@hidden>
;;;
;;; 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)))))
diff --git a/tests/containers.scm b/tests/containers.scm
index 745b56b..0b3a4be 100644
--- a/tests/containers.scm
+++ b/tests/containers.scm
@@ -180,4 +180,31 @@
(lambda ()
(primitive-exit 42))))
+(skip-if-unsupported)
+(test-assert "container-excursion*"
+ (call-with-temporary-directory
+ (lambda (root)
+ (define (namespaces pid)
+ (let ((pid (number->string pid)))
+ (map (lambda (ns)
+ (readlink (string-append "/proc/" pid "/ns/" ns)))
+ '("user" "ipc" "uts" "net" "pid" "mnt"))))
+
+ (let* ((pid (run-container root '()
+ %namespaces 1
+ (lambda ()
+ (sleep 100))))
+ (result (container-excursion* pid
+ (lambda ()
+ (namespaces 1)))))
+ (kill pid SIGKILL)
+ (equal? result (namespaces pid))))))
+
+(skip-if-unsupported)
+(test-equal "container-excursion*, same namespaces"
+ 42
+ (container-excursion* (getpid)
+ (lambda ()
+ (* 6 7))))
+
(test-end)
- branch master updated (a24fda8 -> a062b6c), Ludovic Courtès, 2017/02/06
- 03/09: bash completion: Complete file names after 'guix system COMMAND'., Ludovic Courtès, 2017/02/06
- 06/09: services: bitlbee: Read the PID file., Ludovic Courtès, 2017/02/06
- 05/09: bash completion: Complete subcommands for the current word., Ludovic Courtès, 2017/02/06
- 02/09: bash completion: Complete 'guix gc' with file names., Ludovic Courtès, 2017/02/06
- 07/09: linux-container: Add 'container-excursion*'.,
Ludovic Courtès <=
- 01/09: file-systems: Add '%network-configuration-files' and '%network-file-mappings'., Ludovic Courtès, 2017/02/06
- 04/09: bash completion: Properly complete 'guix container exec'., Ludovic Courtès, 2017/02/06
- 09/09: services: bitlbee: Run in a container., Ludovic Courtès, 2017/02/06
- 08/09: Add (gnu build shepherd)., Ludovic Courtès, 2017/02/06