Skip to content

Commit 913ef36

Browse files
foxharpgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f42ca31 commit 913ef36

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

editor.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cache.h"
22
#include "strbuf.h"
33
#include "run-command.h"
4+
#include "sigchain.h"
45

56
#ifndef DEFAULT_EDITOR
67
#define DEFAULT_EDITOR "vi"
@@ -38,6 +39,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
3839
if (strcmp(editor, ":")) {
3940
const char *args[] = { editor, path, NULL };
4041
struct child_process p;
42+
int ret;
4143

4244
memset(&p, 0, sizeof(p));
4345
p.argv = args;
@@ -46,7 +48,12 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
4648
if (start_command(&p) < 0)
4749
return error("unable to start editor '%s'", editor);
4850

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)
5057
return error("There was a problem with the editor '%s'.",
5158
editor);
5259
}

0 commit comments

Comments
 (0)