From: David Thompson <dthompson2@worcester.edu>
To: guix-devel@gnu.org
Subject: [PATCH] scripts: environment: Properly handle SIGINT.
Date: Sat, 26 Mar 2016 09:08:41 -0400 [thread overview]
Message-ID: <87pouhbd46.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> (raw)
[-- Attachment #1: Type: text/plain, Size: 381 bytes --]
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!
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-scripts-environment-Properly-handle-SIGINT.patch --]
[-- Type: text/x-patch, Size: 2994 bytes --]
From ec7994eec73d322386abbcd901da1b1d2f6f7733 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
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
[-- Attachment #3: Type: text/plain, Size: 20 bytes --]
--
David Thompson
next reply other threads:[~2016-03-26 13:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-26 13:08 David Thompson [this message]
2016-03-26 18:23 ` [PATCH] scripts: environment: Properly handle SIGINT Ludovic Courtès
2016-03-26 18:33 ` Thompson, David
2016-03-26 20:53 ` Thompson, David
2016-03-27 17:35 ` Ludovic Courtès
2016-03-28 16:54 ` Thompson, David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pouhbd46.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me \
--to=dthompson2@worcester.edu \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.