Skip to content
Snippets Groups Projects
Commit 13bc8d5e authored by David Thompson's avatar David Thompson
Browse files

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.
parent c8786834
No related branches found
No related tags found
No related merge requests found
...@@ -358,8 +358,22 @@ (define (launch-environment command inputs paths pure?) ...@@ -358,8 +358,22 @@ (define (launch-environment command inputs paths pure?)
"Run COMMAND in a new environment containing INPUTS, using the native search "Run COMMAND in a new environment containing INPUTS, using the native search
paths defined by the list PATHS. When PURE?, pre-existing environment paths defined by the list PATHS. When PURE?, pre-existing environment
variables are cleared before setting the new ones." variables are cleared before setting the new ones."
;; Properly handle SIGINT, so pressing C-c in an interactive terminal
;; application works.
(sigaction SIGINT SIG_DFL)
(create-environment inputs paths pure?) (create-environment inputs paths pure?)
(apply system* command)) (match command
((program . args)
(apply execlp program program args))))
(define (launch-environment/fork command inputs paths pure?)
"Run COMMAND in a new process with an environment containing INPUTS, using
the native search paths defined by the list PATHS. When PURE?, pre-existing
environment variables are cleared before setting the new ones."
(match (primitive-fork)
(0 (launch-environment command inputs paths pure?))
(pid (match (waitpid pid)
((_ . status) status)))))
(define* (launch-environment/container #:key command bash user-mappings (define* (launch-environment/container #:key command bash user-mappings
profile paths network?) profile paths network?)
...@@ -582,4 +596,5 @@ (define (guix-environment . args) ...@@ -582,4 +596,5 @@ (define (guix-environment . args)
(else (else
(return (return
(exit/status (exit/status
(launch-environment command profile paths pure?))))))))))))) (launch-environment/fork command profile
paths pure?)))))))))))))
...@@ -82,8 +82,13 @@ grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash ...@@ -82,8 +82,13 @@ grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash
rm $tmpdir/mounts rm $tmpdir/mounts
abnormal_exit_code="
(use-modules (system foreign))
;; Purposely make Guile crash with a segfault. :)
(pointer->string (make-pointer 123) 123)"
if guix environment --bootstrap --container \ if guix environment --bootstrap --container \
--ad-hoc bootstrap-binaries -- kill -SEGV 2 --ad-hoc guile-bootstrap -- guile -c "$abnormal_exit_code"
then false; then false;
else else
test $? -gt 127 test $? -gt 127
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment