Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit dd9f303

Browse files
tmdsjanvorli
authored andcommitted
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
1 parent a321506 commit dd9f303

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/pal/src/exception/signal.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void inject_activation_handler(int code, siginfo_t *siginfo, void *contex
9898
#endif
9999
#endif // !HAVE_MACH_EXCEPTIONS
100100

101-
static void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags = 0);
101+
static void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags = 0, bool skipIgnored = false);
102102
static void restore_signal(int signal_id, struct sigaction *previousAction);
103103

104104
/* internal data declarations *********************************************/
@@ -246,8 +246,11 @@ BOOL SEHInitializeSignals(DWORD flags)
246246
handle_signal(SIGBUS, sigbus_handler, &g_previous_sigbus);
247247
// SIGSEGV handler runs on a separate stack so that we can handle stack overflow
248248
handle_signal(SIGSEGV, sigsegv_handler, &g_previous_sigsegv, SA_ONSTACK);
249-
handle_signal(SIGINT, sigint_handler, &g_previous_sigint);
250-
handle_signal(SIGQUIT, sigquit_handler, &g_previous_sigquit);
249+
// We don't setup a handler for SIGINT/SIGQUIT when those signals are ignored.
250+
// Otherwise our child processes would reset to the default on exec causing them
251+
// to terminate on these signals.
252+
handle_signal(SIGINT, sigint_handler, &g_previous_sigint , 0 /* additionalFlags */, true /* skipIgnored */);
253+
handle_signal(SIGQUIT, sigquit_handler, &g_previous_sigquit, 0 /* additionalFlags */, true /* skipIgnored */);
251254

252255
if (!EnsureSignalAlternateStack())
253256
{
@@ -903,7 +906,7 @@ Parameters :
903906
904907
note : if sigfunc is NULL, the default signal handler is restored
905908
--*/
906-
void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags)
909+
void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags, bool skipIgnored)
907910
{
908911
struct sigaction newAction;
909912

@@ -927,6 +930,19 @@ void handle_signal(int signal_id, SIGFUNC sigfunc, struct sigaction *previousAct
927930
}
928931
#endif
929932

933+
if (skipIgnored)
934+
{
935+
if (-1 == sigaction(signal_id, NULL, previousAction))
936+
{
937+
ASSERT("handle_signal: sigaction() call failed with error code %d (%s)\n",
938+
errno, strerror(errno));
939+
}
940+
else if (previousAction->sa_handler == SIG_IGN)
941+
{
942+
return;
943+
}
944+
}
945+
930946
if (-1 == sigaction(signal_id, &newAction, previousAction))
931947
{
932948
ASSERT("handle_signal: sigaction() call failed with error code %d (%s)\n",

0 commit comments

Comments
 (0)