git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Dmitry Potapov <dpotapov@gmail.com>,
	git@vger.kernel.org, Johannes Sixt <j6t@kdbg.org>,
	Joey Hess <joey@kitenet.net>
Subject: Re: RFC: [PATCH] ignore SIGINT&QUIT while waiting for external command
Date: Tue, 19 Oct 2010 14:16:38 -0500	[thread overview]
Message-ID: <20101019191638.GI25139@burratino> (raw)
In-Reply-To: <20101019134040.GA3956@sigill.intra.peff.net>

Jeff King wrote:
> On Tue, Oct 19, 2010 at 09:32:36AM -0400, Jeff King wrote:

>> I think you could just replace your signal() calls with:
>> 
>>   sigchain_push(SIGINT, SIG_IGN);
>>   ...
>>   sigchain_pop(SIGINT);
>
> Which, FWIW, would look like this:

Something in this direction on top?

I think sigchain_push ought to accept a context object.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
diff --git a/run-command.c b/run-command.c
index 24e0f46..efdac84 100644
--- a/run-command.c
+++ b/run-command.c
@@ -103,6 +103,7 @@ static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
 	while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
 		;	/* nothing */
 
+	the_child = NULL;
 	sigchain_pop(SIGINT);
 	sigchain_pop(SIGQUIT);
 
@@ -139,6 +140,19 @@ static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
 	return code;
 }
 
+static struct child_process *the_child;
+
+static void interrupted_with_child(int sig)
+{
+	if (the_child && the_child->pid > 0) {
+		while ((waiting = waitpid(pid, NULL, 0)) < 0 && errno == EINTR)
+			;	/* nothing */
+		the_child = NULL;
+	}
+	sigchain_pop(sig);
+	raise(sig);
+}
+
 int start_command(struct child_process *cmd)
 {
 	int need_in, need_out, need_err;
@@ -206,8 +220,11 @@ fail_pipe:
 		notify_pipe[0] = notify_pipe[1] = -1;
 
 	fflush(NULL);
-	sigchain_push(SIGINT, SIG_IGN);
-	sigchain_push(SIGQUIT, SIG_IGN);
+	if (the_child)
+		die("What?  _Two_ children?");
+	the_child = cmd;
+	sigchain_push(SIGINT, interrupted_with_child);
+	sigchain_push(SIGQUIT, interrupted_with_child);
 	cmd->pid = fork();
 	if (!cmd->pid) {
 		sigchain_pop(SIGINT);

  reply	other threads:[~2010-10-19 19:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-19  4:53 git subcommand sigint gotcha Joey Hess
2010-10-19  9:55 ` Dmitry Potapov
2010-10-19 11:59   ` RFC: [PATCH] ignore SIGINT&QUIT while waiting for external command Dmitry Potapov
2010-10-19 13:32     ` Jeff King
2010-10-19 13:40       ` Jeff King
2010-10-19 19:16         ` Jonathan Nieder [this message]
2010-10-19 19:50           ` Jeff King
2010-10-19 21:06           ` Jakub Narebski
2010-10-19 21:07             ` Jonathan Nieder
2010-10-19 16:31       ` Dmitry Potapov

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=20101019191638.GI25139@burratino \
    --to=jrnieder@gmail.com \
    --cc=dpotapov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=joey@kitenet.net \
    --cc=peff@peff.net \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).