From dd9f303eb0290dbe606a4c6e2da9dcefe97fa5f6 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Thu, 7 Dec 2017 19:08:56 +0100 Subject: [PATCH] Don't change SIGINT/SIGQUIT handling when they are set to SIG_IGN (#15393) * Don't change SIGINT/SIGQUIT handling when they are set to SIG_IGN --- src/pal/src/exception/signal.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/pal/src/exception/signal.cpp b/src/pal/src/exception/signal.cpp index 3f9e19e..012e320 100644 --- a/src/pal/src/exception/signal.cpp +++ b/src/pal/src/exception/signal.cpp @@ -98,7 +98,7 @@ static void inject_activation_handler(int code, siginfo_t *siginfo, void *contex #endif #endif // !HAVE_MACH_EXCEPTIONS -static void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags = 0); +static void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags = 0, bool skipIgnored = false); static void restore_signal(int signal_id, struct sigaction *previousAction); /* internal data declarations *********************************************/ @@ -246,8 +246,11 @@ BOOL SEHInitializeSignals(DWORD flags) handle_signal(SIGBUS, sigbus_handler, &g_previous_sigbus); // SIGSEGV handler runs on a separate stack so that we can handle stack overflow handle_signal(SIGSEGV, sigsegv_handler, &g_previous_sigsegv, SA_ONSTACK); - handle_signal(SIGINT, sigint_handler, &g_previous_sigint); - handle_signal(SIGQUIT, sigquit_handler, &g_previous_sigquit); + // We don't setup a handler for SIGINT/SIGQUIT when those signals are ignored. + // Otherwise our child processes would reset to the default on exec causing them + // to terminate on these signals. + handle_signal(SIGINT, sigint_handler, &g_previous_sigint , 0 /* additionalFlags */, true /* skipIgnored */); + handle_signal(SIGQUIT, sigquit_handler, &g_previous_sigquit, 0 /* additionalFlags */, true /* skipIgnored */); if (!EnsureSignalAlternateStack()) { @@ -903,7 +906,7 @@ Parameters : note : if sigfunc is NULL, the default signal handler is restored --*/ -void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags) +void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags, bool skipIgnored) { struct sigaction newAction; @@ -927,6 +930,19 @@ void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAct } #endif + if (skipIgnored) + { + if (-1 == sigaction(signal_id, NULL, previousAction)) + { + ASSERT("handle_signal: sigaction() call failed with error code %d (%s)\n", + errno, strerror(errno)); + } + else if (previousAction->sa_handler == SIG_IGN) + { + return; + } + } + if (-1 == sigaction(signal_id, &newAction, previousAction)) { ASSERT("handle_signal: sigaction() call failed with error code %d (%s)\n", -- 2.7.4