diff options
author | Paul Fox <pgf@foxharp.boston.ma.us> | 2012-11-30 17:41:26 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-12-02 02:06:04 -0800 |
commit | 913ef36093eac3ec78b5fb155cc2beb5843b1ce5 (patch) | |
tree | 6cf70b5b833f2aadd8c240aefa5afc470766f13f /editor.c | |
parent | f42ca31d8d209a43342ea345a52fc0bd43d71cc8 (diff) | |
download | git-913ef36093eac3ec78b5fb155cc2beb5843b1ce5.tar.gz |
launch_editor: ignore terminal signals while editor has control
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'editor.c')
-rw-r--r-- | editor.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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); } |