From f0828ca6967762e891c6c7dcb01f669afab5fe43 Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Thu, 2 May 2024 18:30:40 +0200 Subject: [PATCH] Make `Ctrl-C` to kill only the command running in the foreground Ignore `INT` signal while executing a command in the foreground and always reset all signal handlers to default in the child process. Fixes #1331 --- NEWS.adoc | 1 + src/display.c | 2 ++ src/io.c | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/NEWS.adoc b/NEWS.adoc index 9096b8a41..012edeedd 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -12,6 +12,7 @@ Bug fixes: - Fix reopening the blame view from the main view. - Fix editing when stdin is redirected. (#1330) - Fix compilation warnings with ncurses 6.5. + - Make `Ctrl-C` to kill only the command running in the foreground. (#1331) tig-2.5.9 --------- diff --git a/src/display.c b/src/display.c index 5152576df..c0322a501 100644 --- a/src/display.c +++ b/src/display.c @@ -84,6 +84,7 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf ok = io_run_bg(argv, dir); } else { + signal(SIGINT, SIG_IGN); clear(); refresh(); endwin(); /* restore original tty modes */ @@ -101,6 +102,7 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf fseek(opt_tty.file, 0, SEEK_END); tcsetattr(opt_tty.fd, TCSAFLUSH, opt_tty.attr); set_terminal_modes(); + signal(SIGINT, SIG_DFL); } if (watch_update(WATCH_EVENT_AFTER_COMMAND) && do_refresh) { diff --git a/src/io.c b/src/io.c index 26ad1c512..4eb7c85a7 100644 --- a/src/io.c +++ b/src/io.c @@ -436,6 +436,13 @@ io_exec(struct io *io, enum io_type type, const char *dir, char * const env[], c putenv(env[i]); } + signal(SIGHUP, SIG_DFL); + signal(SIGINT, SIG_DFL); + signal(SIGPIPE, SIG_DFL); +#ifdef DEBUG + signal(SIGSEGV, SIG_DFL); +#endif + execvp(argv[0], (char *const*) argv); close(STDOUT_FILENO);