Skip to content

Commit

Permalink
Make Ctrl-C to kill only the command running in the foreground
Browse files Browse the repository at this point in the history
Ignore `INT` signal while executing a command in the foreground and
always reset all signal handlers to default in the child process.

Fixes #1331
  • Loading branch information
koutcher committed May 2, 2024
1 parent 58683d0 commit f0828ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
2 changes: 2 additions & 0 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f0828ca

Please sign in to comment.