diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 32bec017f..74dbd22b6 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1014,7 +1014,7 @@ static void test_cancellation() { // Enable fish's signal handling here. We need to make this interactive for fish to install its // signal handlers. proc_push_interactive(1); - signal_set_handlers(true); + signal_set_handlers(); // This tests that we can correctly ctrl-C out of certain loop constructs, and that nothing gets // printed if we do. diff --git a/src/proc.cpp b/src/proc.cpp index 50bfd3fd5..c28f357b4 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -955,15 +955,18 @@ void proc_sanity_check(const parser_t &parser) { void proc_push_interactive(int value) { ASSERT_IS_MAIN_THREAD(); + int old = is_interactive; interactive_stack.push_back(is_interactive); is_interactive = value; - signal_set_handlers_once(is_interactive); + if (old != value) signal_set_handlers(); } void proc_pop_interactive() { ASSERT_IS_MAIN_THREAD(); + int old = is_interactive; is_interactive = interactive_stack.back(); interactive_stack.pop_back(); + if (is_interactive != old) signal_set_handlers(); } void proc_wait_any(parser_t &parser) { diff --git a/src/reader.cpp b/src/reader.cpp index 43ee6f0a2..cf23e944c 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1744,7 +1744,7 @@ static void reader_interactive_init() { } } - signal_set_handlers(shell_is_interactive()); + signal_set_handlers(); } // It shouldn't be necessary to place fish in its own process group and force control diff --git a/src/signal.cpp b/src/signal.cpp index 117cf1343..946961454 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -325,7 +325,7 @@ static void set_interactive_handlers() { } /// Sets up appropriate signal handlers. -void signal_set_handlers(bool interactive) { +void signal_set_handlers() { struct sigaction act; act.sa_flags = 0; sigemptyset(&act.sa_mask); @@ -354,19 +354,11 @@ void signal_set_handlers(bool interactive) { FATAL_EXIT(); } - if (interactive) { + if (shell_is_interactive()) { set_interactive_handlers(); } } -void signal_set_handlers_once(bool interactive) { - static std::once_flag s_noninter_once; - std::call_once(s_noninter_once, signal_set_handlers, false); - - static std::once_flag s_inter_once; - if (interactive) std::call_once(s_inter_once, set_interactive_handlers); -} - void signal_handle(int sig, int do_handle) { struct sigaction act; diff --git a/src/signal.h b/src/signal.h index 3aa8316f6..be0011203 100644 --- a/src/signal.h +++ b/src/signal.h @@ -17,13 +17,7 @@ const wchar_t *signal_get_desc(int sig); void signal_reset_handlers(); /// Set signal handlers to fish default handlers. -/// If \p interactive is set, apply interactive handlers as well. -/// Note interactive handlers, once applied, are not cleared; they are a strict superset of -/// non-interactive handlers. -void signal_set_handlers(bool interactive); - -/// Latch function. This sets signal handlers, but only the first time it is called. -void signal_set_handlers_once(bool interactive); +void signal_set_handlers(); /// Tell fish what to do on the specified signal. ///