diff options
| author | Maxim Cournoyer <maxim@guixotic.coop> | 2025-10-17 23:12:27 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2025-10-29 11:34:28 +0900 |
| commit | 1eccea7ffb7eac43670d5fd76e8afa8ecfe6b0b9 (patch) | |
| tree | 1f40d89649f5449aa3524e2301c186ca94ea73d3 /tests/syscalls.scm | |
| parent | 3966f7629723c68e49b66fdf05feab901f8741ac (diff) | |
build/syscalls: Introduce new safe-clone and use it.
* guix/build/syscalls.scm (without-automatic-finalization): Accept multiple
expressions.
(without-garbage-collection): New syntax.
(without-threads): Likewise.
(ensure-signal-delivery-thread, safe-clone): New procedures.
* tests/syscalls.scm: ("clone and unshare triggers EINVAL")
("safe-clone and unshare succeeds"): New tests.
* gnu/build/linux-container.scm (run-container): Adjust to use 'safe-clone'.
Relates-to: #1169
Change-Id: I044c11a899e24e547a7aed97f30c8e7250ab5363
Diffstat (limited to 'tests/syscalls.scm')
| -rw-r--r-- | tests/syscalls.scm | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/syscalls.scm b/tests/syscalls.scm index 879c3e4f254..a0483e68f08 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> | 3 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> |
| 4 | ;;; Copyright © 2020 Simon South <simon@simonsouth.net> | 4 | ;;; Copyright © 2020 Simon South <simon@simonsouth.net> |
| 5 | ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> | 5 | ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> |
| 6 | ;;; Copyright © 2025 Maxim Cournoyer <maxim@guixotic.coop> | ||
| 6 | ;;; | 7 | ;;; |
| 7 | ;;; This file is part of GNU Guix. | 8 | ;;; This file is part of GNU Guix. |
| 8 | ;;; | 9 | ;;; |
| @@ -29,7 +30,8 @@ | |||
| 29 | #:use-module (srfi srfi-71) | 30 | #:use-module (srfi srfi-71) |
| 30 | #:use-module (system foreign) | 31 | #:use-module (system foreign) |
| 31 | #:use-module ((ice-9 ftw) #:select (scandir)) | 32 | #:use-module ((ice-9 ftw) #:select (scandir)) |
| 32 | #:use-module (ice-9 match)) | 33 | #:use-module (ice-9 match) |
| 34 | #:use-module (ice-9 threads)) | ||
| 33 | 35 | ||
| 34 | ;; Test the (guix build syscalls) module, although there's not much that can | 36 | ;; Test the (guix build syscalls) module, although there's not much that can |
| 35 | ;; actually be tested without being root. | 37 | ;; actually be tested without being root. |
| @@ -158,6 +160,38 @@ | |||
| 158 | (lambda args | 160 | (lambda args |
| 159 | (system-error-errno args)))) | 161 | (system-error-errno args)))) |
| 160 | 162 | ||
| 163 | (define child-thunk | ||
| 164 | (lambda () | ||
| 165 | (gc) ;spawn GC threads | ||
| 166 | (primitive-exit | ||
| 167 | (catch 'system-error | ||
| 168 | (lambda () | ||
| 169 | (unshare CLONE_THREAD) | ||
| 170 | 0) ;no error | ||
| 171 | (lambda args | ||
| 172 | (system-error-errno args)))))) | ||
| 173 | |||
| 174 | (define parent-proc | ||
| 175 | (lambda (pid) | ||
| 176 | (match (waitpid pid) | ||
| 177 | ((_ . status) | ||
| 178 | (status:exit-val status))))) | ||
| 179 | |||
| 180 | (unless perform-container-tests? | ||
| 181 | (test-skip 1)) | ||
| 182 | (test-equal "clone and unshare triggers EINVAL" | ||
| 183 | EINVAL | ||
| 184 | (match (clone (logior CLONE_NEWUSER SIGCHLD)) | ||
| 185 | (0 (child-thunk)) | ||
| 186 | (pid (parent-proc pid)))) | ||
| 187 | |||
| 188 | (unless perform-container-tests? | ||
| 189 | (test-skip 1)) | ||
| 190 | (test-equal "safe-clone and unshare succeeds" | ||
| 191 | 0 | ||
| 192 | (safe-clone (logior CLONE_NEWUSER SIGCHLD) | ||
| 193 | child-thunk parent-proc)) | ||
| 194 | |||
| 161 | (unless perform-container-tests? | 195 | (unless perform-container-tests? |
| 162 | (test-skip 1)) | 196 | (test-skip 1)) |
| 163 | (test-assert "setns" | 197 | (test-assert "setns" |
