diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2023-01-30 22:20:18 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2023-01-30 22:24:27 +0100 |
| commit | 0ef8fe22ed8985c9656835fc25ab3463d55b6669 (patch) | |
| tree | 87f453456f8d29da3c4eca9f8f495e17ce9a3d97 /tests/containers.scm | |
| parent | 52eb3db19cb9e5c294c86a8552a4baaa5b473672 (diff) | |
linux-container: 'container-excursion' forks to join the PID namespace.
Fixes <https://issues.guix.gnu.org/61156>.
* gnu/build/linux-container.scm (container-excursion): Add extra call to
'primitive-fork' and invoke THUNK in the child process.
* tests/containers.scm ("container-excursion"): Remove extra
'primitive-fork' call, now unnecessary.
("container-excursion*, /proc"): New test.
Diffstat (limited to 'tests/containers.scm')
| -rw-r--r-- | tests/containers.scm | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/tests/containers.scm b/tests/containers.scm index 1378b10f22b..70d5ba2d309 100644 --- a/tests/containers.scm +++ b/tests/containers.scm | |||
| @@ -1,6 +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 © 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org> | 3 | ;;; Copyright © 2016, 2017, 2019, 2023 Ludovic Courtès <ludo@gnu.org> |
| 4 | ;;; | 4 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| 6 | ;;; | 6 | ;;; |
| @@ -31,7 +31,8 @@ | |||
| 31 | #:use-module (guix tests) | 31 | #:use-module (guix tests) |
| 32 | #:use-module (srfi srfi-1) | 32 | #:use-module (srfi srfi-1) |
| 33 | #:use-module (srfi srfi-64) | 33 | #:use-module (srfi srfi-64) |
| 34 | #:use-module (ice-9 match)) | 34 | #:use-module (ice-9 match) |
| 35 | #:use-module ((ice-9 ftw) #:select (scandir))) | ||
| 35 | 36 | ||
| 36 | (define (assert-exit x) | 37 | (define (assert-exit x) |
| 37 | (primitive-exit (if x 0 1))) | 38 | (primitive-exit (if x 0 1))) |
| @@ -176,21 +177,11 @@ | |||
| 176 | (close start-in) | 177 | (close start-in) |
| 177 | (container-excursion pid | 178 | (container-excursion pid |
| 178 | (lambda () | 179 | (lambda () |
| 179 | ;; Fork again so that the pid is within the context of | 180 | ;; Check that all of the namespace identifiers are |
| 180 | ;; the joined pid namespace instead of the original pid | 181 | ;; the same as the container process. |
| 181 | ;; namespace. | 182 | (assert-exit |
| 182 | (match (primitive-fork) | 183 | (equal? container-namespaces |
| 183 | (0 | 184 | (namespaces (getpid))))))))) |
| 184 | ;; Check that all of the namespace identifiers are | ||
| 185 | ;; the same as the container process. | ||
| 186 | (assert-exit | ||
| 187 | (equal? container-namespaces | ||
| 188 | (namespaces (getpid))))) | ||
| 189 | (fork-pid | ||
| 190 | (match (waitpid fork-pid) | ||
| 191 | ((_ . status) | ||
| 192 | (primitive-exit | ||
| 193 | (status:exit-val status))))))))))) | ||
| 194 | (close end-in) | 185 | (close end-in) |
| 195 | ;; Stop the container. | 186 | ;; Stop the container. |
| 196 | (write 'done end-out) | 187 | (write 'done end-out) |
| @@ -237,6 +228,27 @@ | |||
| 237 | (* 6 7)))) | 228 | (* 6 7)))) |
| 238 | 229 | ||
| 239 | (skip-if-unsupported) | 230 | (skip-if-unsupported) |
| 231 | (test-equal "container-excursion*, /proc" | ||
| 232 | '("1" "2") | ||
| 233 | (call-with-temporary-directory | ||
| 234 | (lambda (root) | ||
| 235 | (let* ((pid (run-container root '() | ||
| 236 | %namespaces 1 | ||
| 237 | (lambda () | ||
| 238 | (sleep 100)))) | ||
| 239 | (result (container-excursion* pid | ||
| 240 | (lambda () | ||
| 241 | ;; We expect to see exactly two processes in this | ||
| 242 | ;; namespace. | ||
| 243 | (scandir "/proc" | ||
| 244 | (lambda (file) | ||
| 245 | (char-set-contains? | ||
| 246 | char-set:digit | ||
| 247 | (string-ref file 0)))))))) | ||
| 248 | (kill pid SIGKILL) | ||
| 249 | result)))) | ||
| 250 | |||
| 251 | (skip-if-unsupported) | ||
| 240 | (test-equal "eval/container, exit status" | 252 | (test-equal "eval/container, exit status" |
| 241 | 42 | 253 | 42 |
| 242 | (let* ((store (open-connection-for-tests)) | 254 | (let* ((store (open-connection-for-tests)) |
