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>
Paul Fox committed
Nov 30, 2012 at 17:41 UTC
913ef36093eac3ec78b5fb155cc2beb5843b1ce5
1 file changed
+8
-1
editor.c
+8
-1
@@ -1,6 +1,7 @@
1
#include "cache.h"
2
#include "strbuf.h"
3
#include "run-command.h"
4
+#include "sigchain.h"
5
6
#ifndef DEFAULT_EDITOR
7
#define DEFAULT_EDITOR "vi"
@@ -38,6 +39,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
39
if (strcmp(editor, ":")) {
40
const char *args[] = { editor, path, NULL };
41
struct child_process p;
42
+ int ret;
43
44
memset(&p, 0, sizeof(p));
45
p.argv = args;
@@ -46,7 +48,12 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
48
if (start_command(&p) < 0)
49
return error("unable to start editor '%s'", editor);
50
49
- if (finish_command(&p))
51
+ sigchain_push(SIGINT, SIG_IGN);
52
+ sigchain_push(SIGQUIT, SIG_IGN);
53
+ ret = finish_command(&p);
54
+ sigchain_pop(SIGINT);
55
+ sigchain_pop(SIGQUIT);
56
+ if (ret)
57
return error("There was a problem with the editor '%s'.",
58
editor);
59
}