Skip to content

Commit 1250857

Browse files
peffgitster
authored andcommitted
launch_editor: propagate signals from editor to git
We block SIGINT and SIGQUIT while the editor runs so that git is not killed accidentally by a stray "^C" meant for the editor or its subprocesses. This works because most editors ignore SIGINT. However, some editor wrappers, like emacsclient, expect to die due to ^C. We detect the signal death in the editor and properly exit, but not before writing a useless error message to stderr. Instead, let's notice when the editor was killed by a terminal signal and just raise the signal on ourselves. This skips the message and looks to our parent like we received SIGINT ourselves. The end effect is that if the user's editor ignores SIGINT, we will, too. And if it does not, then we will behave as if we did not ignore it. That should make all users happy. Note that in the off chance that another part of git has ignored SIGINT while calling launch_editor, we will still properly detect and propagate the failed return code from the editor (i.e., the worst case is that we generate the useless error, not fail to notice the editor's death). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2767c5 commit 1250857

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

editor.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
3939
if (strcmp(editor, ":")) {
4040
const char *args[] = { editor, path, NULL };
4141
struct child_process p;
42-
int ret;
42+
int ret, sig;
4343

4444
memset(&p, 0, sizeof(p));
4545
p.argv = args;
@@ -51,8 +51,11 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
5151
sigchain_push(SIGINT, SIG_IGN);
5252
sigchain_push(SIGQUIT, SIG_IGN);
5353
ret = finish_command(&p);
54+
sig = ret + 128;
5455
sigchain_pop(SIGINT);
5556
sigchain_pop(SIGQUIT);
57+
if (sig == SIGINT || sig == SIGQUIT)
58+
raise(sig);
5659
if (ret)
5760
return error("There was a problem with the editor '%s'.",
5861
editor);

0 commit comments

Comments
 (0)