[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/01: environment: Properly handle SIGINT.
From: |
David Thompson |
Subject: |
01/01: environment: Properly handle SIGINT. |
Date: |
Sun, 27 Mar 2016 21:39:33 +0000 |
davexunit pushed a commit to branch master
in repository guix.
commit 13bc8d5e4f842fe595306c22c99a5868d8016318
Author: David Thompson <address@hidden>
Date: Sat Mar 26 08:45:08 2016 -0400
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.
---
guix/scripts/environment.scm | 19 +++++++++++++++++--
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 0d5cab4..fc75d78 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?)))))))))))))
diff --git a/tests/guix-environment-container.sh
b/tests/guix-environment-container.sh
index aba34a3..0a7ea48 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
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 \
- --ad-hoc bootstrap-binaries -- kill -SEGV 2
+ --ad-hoc guile-bootstrap -- guile -c "$abnormal_exit_code"
then false;
else
test $? -gt 127