[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] scripts: environment: Properly handle SIGINT.
From: |
David Thompson |
Subject: |
[PATCH] scripts: environment: Properly handle SIGINT. |
Date: |
Sat, 26 Mar 2016 09:08:41 -0400 |
User-agent: |
Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-unknown-linux-gnu) |
Has anyone ever been really annoyed that C-c doesn't work in a bash
shell spawned by 'guix environment'? Me too! And I finally got around
to fixing it. I would like to get this in before 0.10.0 is released.
Ludo, I removed one of the tests in guix-environment-container.sh
because it seems obsolete to me now. Let me know if you think of
another test to replace it.
Thanks!
>From ec7994eec73d322386abbcd901da1b1d2f6f7733 Mon Sep 17 00:00:00 2001
From: David Thompson <address@hidden>
Date: Sat, 26 Mar 2016 08:45:08 -0400
Subject: [PATCH] scripts: 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: Remove obsolete test.
---
guix/scripts/environment.scm | 19 +++++++++++++++++--
tests/guix-environment-container.sh | 7 -------
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index ee8f6b1..d554ca2 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..da4c6fc 100644
--- a/tests/guix-environment-container.sh
+++ b/tests/guix-environment-container.sh
@@ -81,10 +81,3 @@ grep $(guix build guile-bootstrap) $tmpdir/mounts
grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash
rm $tmpdir/mounts
-
-if guix environment --bootstrap --container \
- --ad-hoc bootstrap-binaries -- kill -SEGV 2
-then false;
-else
- test $? -gt 127
-fi
--
2.7.3
--
David Thompson
- [PATCH] scripts: environment: Properly handle SIGINT.,
David Thompson <=