summaryrefslogtreecommitdiff
path: root/guix/scripts
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-03-26 08:45:08 -0400
committerDavid Thompson <dthompson2@worcester.edu>2016-03-27 15:09:21 -0400
commit13bc8d5e4f842fe595306c22c99a5868d8016318 (patch)
treeaa68f2d597da1bcb8a34eabf83f8c06a4181d63f /guix/scripts
parentc8786834ef53501e4ef0090b95520e4cefbe5b7b (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.
Diffstat (limited to 'guix/scripts')
-rw-r--r--guix/scripts/environment.scm19
1 files changed, 17 insertions, 2 deletions
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 0d5cab432c..fc75d78611 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -358,8 +358,22 @@ and suitable for 'exit'."
"Run COMMAND in a new 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."
+ ;; Properly handle SIGINT, so pressing C-c in an interactive terminal
+ ;; application works.
+ (sigaction SIGINT SIG_DFL)
(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
profile paths network?)
@@ -582,4 +596,5 @@ message if any test fails."
(else
(return
(exit/status
- (launch-environment command profile paths pure?)))))))))))))
+ (launch-environment/fork command profile
+ paths pure?)))))))))))))