mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-31 08:55:15 +08:00
Unify the interactive and non-interactive signal handlers
The signal handlers for interactive and non-interactive SIGINT were distinct and talked to the reader. This wasn't really justified and will complicate having multiple threads. Unify these into a single signal handler.
This commit is contained in:
parent
5a4df9dd3a
commit
d729d57d94
|
@ -251,14 +251,6 @@ static void handle_int(int sig, siginfo_t *info, void *context) {
|
||||||
topic_monitor_t::principal().post(topic_t::sighupint);
|
topic_monitor_t::principal().post(topic_t::sighupint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Non-interactive ^C handler.
|
|
||||||
static void handle_int_notinteractive(int sig, siginfo_t *info, void *context) {
|
|
||||||
if (reraise_if_forked_child(sig)) return;
|
|
||||||
parser_t::skip_all_blocks();
|
|
||||||
default_handler(sig, info, context);
|
|
||||||
topic_monitor_t::principal().post(topic_t::sighupint);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// sigchld handler. Does notification and calls the handler in proc.c.
|
/// sigchld handler. Does notification and calls the handler in proc.c.
|
||||||
static void handle_chld(int sig, siginfo_t *info, void *context) {
|
static void handle_chld(int sig, siginfo_t *info, void *context) {
|
||||||
if (reraise_if_forked_child(sig)) return;
|
if (reraise_if_forked_child(sig)) return;
|
||||||
|
@ -300,7 +292,6 @@ static void set_interactive_handlers() {
|
||||||
// Interactive mode. Ignore interactive signals. We are a shell, we know what is best for
|
// Interactive mode. Ignore interactive signals. We are a shell, we know what is best for
|
||||||
// the user.
|
// the user.
|
||||||
act.sa_handler = SIG_IGN;
|
act.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGINT, &act, NULL);
|
|
||||||
sigaction(SIGQUIT, &act, NULL);
|
sigaction(SIGQUIT, &act, NULL);
|
||||||
sigaction(SIGTSTP, &act, NULL);
|
sigaction(SIGTSTP, &act, NULL);
|
||||||
sigaction(SIGTTOU, &act, NULL);
|
sigaction(SIGTTOU, &act, NULL);
|
||||||
|
@ -310,10 +301,6 @@ static void set_interactive_handlers() {
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGTTIN, &act, NULL);
|
sigaction(SIGTTIN, &act, NULL);
|
||||||
|
|
||||||
act.sa_sigaction = &handle_int;
|
|
||||||
act.sa_flags = SA_SIGINFO;
|
|
||||||
sigaction(SIGINT, &act, NULL);
|
|
||||||
|
|
||||||
// SIGTERM restores the terminal controlling process before dying.
|
// SIGTERM restores the terminal controlling process before dying.
|
||||||
act.sa_sigaction = &handle_sigterm;
|
act.sa_sigaction = &handle_sigterm;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
|
@ -345,10 +332,6 @@ static void set_non_interactive_handlers() {
|
||||||
|
|
||||||
act.sa_handler = SIG_IGN;
|
act.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGQUIT, &act, 0);
|
sigaction(SIGQUIT, &act, 0);
|
||||||
|
|
||||||
act.sa_sigaction = &handle_int_notinteractive;
|
|
||||||
act.sa_flags = SA_SIGINFO;
|
|
||||||
sigaction(SIGINT, &act, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets up appropriate signal handlers.
|
/// Sets up appropriate signal handlers.
|
||||||
|
@ -359,9 +342,15 @@ void signal_set_handlers() {
|
||||||
|
|
||||||
// Ignore SIGPIPE. We'll detect failed writes and deal with them appropriately. We don't want
|
// Ignore SIGPIPE. We'll detect failed writes and deal with them appropriately. We don't want
|
||||||
// this signal interrupting other syscalls or terminating us.
|
// this signal interrupting other syscalls or terminating us.
|
||||||
|
act.sa_sigaction = nullptr;
|
||||||
act.sa_handler = SIG_IGN;
|
act.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGPIPE, &act, 0);
|
sigaction(SIGPIPE, &act, 0);
|
||||||
|
|
||||||
|
// Apply our SIGINT handler.
|
||||||
|
act.sa_sigaction = &handle_int;
|
||||||
|
act.sa_flags = SA_SIGINFO;
|
||||||
|
sigaction(SIGINT, &act, NULL);
|
||||||
|
|
||||||
// Whether or not we're interactive we want SIGCHLD to not interrupt restartable syscalls.
|
// Whether or not we're interactive we want SIGCHLD to not interrupt restartable syscalls.
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
act.sa_sigaction = &handle_chld;
|
act.sa_sigaction = &handle_chld;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user