git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC] launch_editor: ignore SIGINT while the editor has control
@ 2012-11-07 19:16 Paul Fox
  2012-11-07 22:00 ` Krzysztof Mazur
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Fox @ 2012-11-07 19:16 UTC (permalink / raw)
  To: git; +Cc: gitster

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.)

Signed-off-by: Paul Fox <pgf@foxharp.boston.ma.us>
---

i often shell out of my editor while composing a git commit message,
in order to recheck the diffs or the log, do a final test build, etc.
when i interrupt one of these operations, the spawned program gets
killed.  in addition git itself gets killed, which in turn kills my
editor.  this is never what i intended.  :-)

the problem is easy to demonstrate with vim, vile, or em.  in a vi-like
editor:
    git commit foo
    :!sleep 10
    ^C

both CVS and my usual mailer (MH) protect against this behavior when
spawning editors by using code similar to the patch below, which
causes the spawning process to ignore SIGINT while the editor is
running.

i looked at the other invocations of run_command_v_opt_xxx() in git,
but couldn't convince myself that any of the others needed similar
protection.  i also couldn't convince myself that i wouldn't cause
collateral damage if i tried moving the sigchain_push/pop into
run-command.c.  (but perhaps it's simple -- maybe the RUN_USING_SHELL
flag should always imply this behavior.)

the patch is against current master.

paul

 editor.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/editor.c b/editor.c
index d834003..775f22d 100644
--- a/editor.c
+++ b/editor.c
@@ -37,8 +37,12 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
 
 	if (strcmp(editor, ":")) {
 		const char *args[] = { editor, path, NULL };
+		int ret;
 
-		if (run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env))
+		sigchain_push(SIGINT, SIG_IGN);
+		ret = run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env);
+		sigchain_pop(SIGINT);
+		if (ret)
 			return error("There was a problem with the editor '%s'.",
 					editor);
 	}
-- 
1.7.5.4


=---------------------
 paul fox, pgf@foxharp.boston.ma.us (arlington, ma, where it's 31.8 degrees)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-11-08 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-07 19:16 [PATCH/RFC] launch_editor: ignore SIGINT while the editor has control Paul Fox
2012-11-07 22:00 ` Krzysztof Mazur
2012-11-07 23:35   ` Paul Fox
2012-11-08 15:33     ` Jeff King

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).