[PATCH 2/5] launch_editor: ignore SIGINT while the editor has control
- From
Jeff King <peff@peff.net>
- Date
- Nov 11, 2012, 16:58 UTC
- Message-ID
- <20121111165855.GA19962@sigill.intra.peff.net>
- In-Reply-To
- <20121111163100.GB13188@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).
Signed-off-by: Paul Fox <pgf@foxharp.boston.ma.us> Signed-off-by: Jeff King <peff@peff.net> --- Whoops, my original sending of this actually had Paul in the email's From field, not in the pseudo-header of the commit. Apologies if you receive an extra forged copy.
editor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/editor.c b/editor.c index 842f782..28aae85 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,10 @@ 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); + ret = finish_command(&p); + sigchain_pop(SIGINT); + if (ret) return error("There was a problem with the editor '%s'.", editor); }
-- 1.8.0.207.gdf2154c