git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RFC: [PATCH] ignore SIGINT&QUIT while waiting for external command

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 19, 2010, 19:16 UTC
Message-ID
<20101019191638.GI25139@burratino>
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:
Show 7 quoted lines
>> 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);
Previous: Jeff KingNext: Jeff King
Message 6 of 10 in “git subcommand sigint gotcha”
  1. Joey HessOct 19, 2010
  2. Dmitry PotapovOct 19, 2010
  3. RFC: [PATCH] ignore SIGINT&QUIT while waiting for external commandDmitry Potapov, Oct 19, 2010
  4. Jeff KingOct 19, 2010
  5. Jeff KingOct 19, 2010
  6. Jonathan NiederOct 19, 2010
  7. Jeff KingOct 19, 2010
  8. Jakub NarebskiOct 19, 2010
  9. Jonathan NiederOct 19, 2010
  10. Dmitry PotapovOct 19, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.