From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Thompson Subject: [PATCH] scripts: environment: Properly handle SIGINT. Date: Sat, 26 Mar 2016 09:08:41 -0400 Message-ID: <87pouhbd46.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ajnxQ-0002Sc-4Z for guix-devel@gnu.org; Sat, 26 Mar 2016 09:08:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ajnxL-0000mc-LX for guix-devel@gnu.org; Sat, 26 Mar 2016 09:08:48 -0400 Received: from mail-qg0-x22b.google.com ([2607:f8b0:400d:c04::22b]:34852) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ajnxL-0000mQ-CY for guix-devel@gnu.org; Sat, 26 Mar 2016 09:08:43 -0400 Received: by mail-qg0-x22b.google.com with SMTP id y89so77874075qge.2 for ; Sat, 26 Mar 2016 06:08:43 -0700 (PDT) Received: from izanagi (209-6-40-86.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com. [209.6.40.86]) by smtp.gmail.com with ESMTPSA id x136sm7695334qka.0.2016.03.26.06.08.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Mar 2016 06:08:42 -0700 (PDT) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain 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! --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-scripts-environment-Properly-handle-SIGINT.patch >From ec7994eec73d322386abbcd901da1b1d2f6f7733 Mon Sep 17 00:00:00 2001 From: David Thompson 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 --=-=-= Content-Type: text/plain -- David Thompson --=-=-=--