From d729d57d94565fff9777ccbc56dc3ecfad1fbc85 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 26 May 2019 00:32:11 -0700 Subject: [PATCH] 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. --- src/signal.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/signal.cpp b/src/signal.cpp index 8e2be099f..9405ce887 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -251,14 +251,6 @@ static void handle_int(int sig, siginfo_t *info, void *context) { 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. static void handle_chld(int sig, siginfo_t *info, void *context) { 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 // the user. act.sa_handler = SIG_IGN; - sigaction(SIGINT, &act, NULL); sigaction(SIGQUIT, &act, NULL); sigaction(SIGTSTP, &act, NULL); sigaction(SIGTTOU, &act, NULL); @@ -310,10 +301,6 @@ static void set_interactive_handlers() { act.sa_flags = SA_SIGINFO; 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. act.sa_sigaction = &handle_sigterm; act.sa_flags = SA_SIGINFO; @@ -345,10 +332,6 @@ static void set_non_interactive_handlers() { act.sa_handler = SIG_IGN; sigaction(SIGQUIT, &act, 0); - - act.sa_sigaction = &handle_int_notinteractive; - act.sa_flags = SA_SIGINFO; - sigaction(SIGINT, &act, NULL); } /// 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 // this signal interrupting other syscalls or terminating us. + act.sa_sigaction = nullptr; act.sa_handler = SIG_IGN; 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. act.sa_flags = SA_SIGINFO; act.sa_sigaction = &handle_chld;