Skip to content

Commit d5b9585

Browse files
committed
Merge branch 'pf/editor-ignore-sigint'
The behaviour visible to the end users was confusing, when they attempt to kill a process spawned in the editor that was in turn launched by Git with SIGINT (or SIGQUIT), as Git would catch that signal and die. We ignore these signals now. * pf/editor-ignore-sigint: launch_editor: propagate signals from editor to git run-command: do not warn about child death from terminal launch_editor: ignore terminal signals while editor has control launch_editor: refactor to use start/finish_command run-command: drop silent_exec_failure arg from wait_or_whine
2 parents 5f07937 + 1250857 commit d5b9585

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

editor.c

Lines changed: 19 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"
@@ -37,8 +38,25 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
3738

3839
if (strcmp(editor, ":")) {
3940
const char *args[] = { editor, path, NULL };
41+
struct child_process p;
42+
int ret, sig;
4043

41-
if (run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env))
44+
memset(&p, 0, sizeof(p));
45+
p.argv = args;
46+
p.env = env;
47+
p.use_shell = 1;
48+
if (start_command(&p) < 0)
49+
return error("unable to start editor '%s'", editor);
50+
51+
sigchain_push(SIGINT, SIG_IGN);
52+
sigchain_push(SIGQUIT, SIG_IGN);
53+
ret = finish_command(&p);
54+
sig = ret + 128;
55+
sigchain_pop(SIGINT);
56+
sigchain_pop(SIGQUIT);
57+
if (sig == SIGINT || sig == SIGQUIT)
58+
raise(sig);
59+
if (ret)
4260
return error("There was a problem with the editor '%s'.",
4361
editor);
4462
}

run-command.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static inline void set_cloexec(int fd)
226226
fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
227227
}
228228

229-
static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
229+
static int wait_or_whine(pid_t pid, const char *argv0)
230230
{
231231
int status, code = -1;
232232
pid_t waiting;
@@ -242,7 +242,8 @@ static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
242242
error("waitpid is confused (%s)", argv0);
243243
} else if (WIFSIGNALED(status)) {
244244
code = WTERMSIG(status);
245-
error("%s died of signal %d", argv0, code);
245+
if (code != SIGINT && code != SIGQUIT)
246+
error("%s died of signal %d", argv0, code);
246247
/*
247248
* This return value is chosen so that code & 0xff
248249
* mimics the exit code that a POSIX shell would report for
@@ -432,8 +433,7 @@ int start_command(struct child_process *cmd)
432433
* At this point we know that fork() succeeded, but execvp()
433434
* failed. Errors have been reported to our stderr.
434435
*/
435-
wait_or_whine(cmd->pid, cmd->argv[0],
436-
cmd->silent_exec_failure);
436+
wait_or_whine(cmd->pid, cmd->argv[0]);
437437
failed_errno = errno;
438438
cmd->pid = -1;
439439
}
@@ -538,7 +538,7 @@ int start_command(struct child_process *cmd)
538538

539539
int finish_command(struct child_process *cmd)
540540
{
541-
return wait_or_whine(cmd->pid, cmd->argv[0], cmd->silent_exec_failure);
541+
return wait_or_whine(cmd->pid, cmd->argv[0]);
542542
}
543543

544544
int run_command(struct child_process *cmd)

0 commit comments

Comments
 (0)