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

[PATCH 3/5] launch_editor: ignore terminal signals while editor has control

From
Jeff King <peff@peff.net>
Date
Nov 30, 2012, 22:41 UTC
Message-ID
<20121130224125.GC23772@sigill.intra.peff.net>
In-Reply-To
<20121130223943.GA27120@sigill.intra.peff.net>
From: Paul Fox <pgf@foxharp.boston.ma.us>

The user's editor likely catches SIGINT (ctrl-C). but if the user spawns a command from the editor and uses ctrl-C to kill that command, the SIGINT will likely also kill git itself (depending on the editor, this can leave the terminal in an unusable state).

Let's ignore it while the editor is running, and do the same for SIGQUIT, which many editors also ignore. This matches the behavior if we were to use system(3) instead of run-command.

Signed-off-by: Paul Fox <pgf@foxharp.boston.ma.us>
Signed-off-by: Jeff King <peff@peff.net>
---
 editor.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/editor.c b/editor.c
index 842f782..c892a81 100644
--- a/editor.c
+++ b/editor.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "strbuf.h"
 #include "run-command.h"
+#include "sigchain.h"
 
 #ifndef DEFAULT_EDITOR
 #define DEFAULT_EDITOR "vi"
@@ -38,6 +39,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
 	if (strcmp(editor, ":")) {
 		const char *args[] = { editor, path, NULL };
 		struct child_process p;
+		int ret;
 
 		memset(&p, 0, sizeof(p));
 		p.argv = args;
@@ -46,7 +48,12 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
 		if (start_command(&p) < 0)
 			return error("unable to start editor '%s'", editor);
 
-		if (finish_command(&p))
+		sigchain_push(SIGINT, SIG_IGN);
+		sigchain_push(SIGQUIT, SIG_IGN);
+		ret = finish_command(&p);
+		sigchain_pop(SIGINT);
+		sigchain_pop(SIGQUIT);
+		if (ret)
 			return error("There was a problem with the editor '%s'.",
 					editor);
 	}
-- 
1.8.0.1.620.g558b0aa
Previous: Jeff KingNext: Jeff King
Message 4 of 9 in “ignore SIG{INT,QUIT} when launching editor”
  1. 0/5 ignore SIG{INT,QUIT} when launching editorJeff King, Nov 30, 2012
  2. 1/5 run-command: drop silent_exec_failure arg from wait_or_whineJeff King, Nov 30, 2012
  3. 2/5 launch_editor: refactor to use start/finish_commandJeff King, Nov 30, 2012
  4. 3/5 launch_editor: ignore terminal signals while editor has controlJeff King, Nov 30, 2012
  5. 4/5 run-command: do not warn about child death from terminalJeff King, Nov 30, 2012
  6. 5/5 launch_editor: propagate signals from editor to gitJeff King, Nov 30, 2012
  7. Krzysztof MazurDec 1, 2012
  8. Paul FoxDec 1, 2012
  9. Junio C HamanoDec 2, 2012

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.