diff options
| author | David Thompson <dthompson2@worcester.edu> | 2016-03-26 08:45:08 -0400 |
|---|---|---|
| committer | David Thompson <dthompson2@worcester.edu> | 2016-03-27 15:09:21 -0400 |
| commit | 13bc8d5e4f842fe595306c22c99a5868d8016318 (patch) | |
| tree | aa68f2d597da1bcb8a34eabf83f8c06a4181d63f | |
| parent | c8786834ef53501e4ef0090b95520e4cefbe5b7b (diff) | |
environment: Properly handle SIGINT.
Switching to execlp means that the process spawned in a container is PID
1, which obsoleted one of the 'guix environment --container' tests
because the init process can't be killed in the usual manner.
* guix/scripts/environment.scm (launch-environment/fork): New procedure.
(launch-environment): Switch from system* to execlp. Add handler for
SIGINT.
(guix-environment): Use launch-environment/fork.
* tests/guix-environment-container.sh: Replace abnormal exit test with
one that works now that the spawned process is PID 1.
| -rw-r--r-- | guix/scripts/environment.scm | 19 | ||||
| -rw-r--r-- | tests/guix-environment-container.sh | 7 |
2 files changed, 23 insertions, 3 deletions
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 0d5cab432c9..fc75d786115 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm | |||
| @@ -358,8 +358,22 @@ and suitable for 'exit'." | |||
| 358 | "Run COMMAND in a new environment containing INPUTS, using the native search | 358 | "Run COMMAND in a new environment containing INPUTS, using the native search |
| 359 | paths defined by the list PATHS. When PURE?, pre-existing environment | 359 | paths defined by the list PATHS. When PURE?, pre-existing environment |
| 360 | variables are cleared before setting the new ones." | 360 | variables are cleared before setting the new ones." |
| 361 | ;; Properly handle SIGINT, so pressing C-c in an interactive terminal | ||
| 362 | ;; application works. | ||
| 363 | (sigaction SIGINT SIG_DFL) | ||
| 361 | (create-environment inputs paths pure?) | 364 | (create-environment inputs paths pure?) |
| 362 | (apply system* command)) | 365 | (match command |
| 366 | ((program . args) | ||
| 367 | (apply execlp program program args)))) | ||
| 368 | |||
| 369 | (define (launch-environment/fork command inputs paths pure?) | ||
| 370 | "Run COMMAND in a new process with an environment containing INPUTS, using | ||
| 371 | the native search paths defined by the list PATHS. When PURE?, pre-existing | ||
| 372 | environment variables are cleared before setting the new ones." | ||
| 373 | (match (primitive-fork) | ||
| 374 | (0 (launch-environment command inputs paths pure?)) | ||
| 375 | (pid (match (waitpid pid) | ||
| 376 | ((_ . status) status))))) | ||
| 363 | 377 | ||
| 364 | (define* (launch-environment/container #:key command bash user-mappings | 378 | (define* (launch-environment/container #:key command bash user-mappings |
| 365 | profile paths network?) | 379 | profile paths network?) |
| @@ -582,4 +596,5 @@ message if any test fails." | |||
| 582 | (else | 596 | (else |
| 583 | (return | 597 | (return |
| 584 | (exit/status | 598 | (exit/status |
| 585 | (launch-environment command profile paths pure?))))))))))))) | 599 | (launch-environment/fork command profile |
| 600 | paths pure?))))))))))))) | ||
diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index aba34a3bd0a..0a7ea481fca 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh | |||
| @@ -82,8 +82,13 @@ grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash | |||
| 82 | 82 | ||
| 83 | rm $tmpdir/mounts | 83 | rm $tmpdir/mounts |
| 84 | 84 | ||
| 85 | abnormal_exit_code=" | ||
| 86 | (use-modules (system foreign)) | ||
| 87 | ;; Purposely make Guile crash with a segfault. :) | ||
| 88 | (pointer->string (make-pointer 123) 123)" | ||
| 89 | |||
| 85 | if guix environment --bootstrap --container \ | 90 | if guix environment --bootstrap --container \ |
| 86 | --ad-hoc bootstrap-binaries -- kill -SEGV 2 | 91 | --ad-hoc guile-bootstrap -- guile -c "$abnormal_exit_code" |
| 87 | then false; | 92 | then false; |
| 88 | else | 93 | else |
| 89 | test $? -gt 127 | 94 | test $? -gt 127 |
