Skip to content

Commit 07cb9ef

Browse files
committed
src: don't reset embeder signal handlers
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix #47013
1 parent 1640aeb commit 07cb9ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/node.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ void ResetSignalHandlers() {
430430
if (nr == SIGKILL || nr == SIGSTOP)
431431
continue;
432432
act.sa_handler = (nr == SIGPIPE || nr == SIGXFSZ) ? SIG_IGN : SIG_DFL;
433+
if (act.sa_handler == SIG_DFL) {
434+
// The only bad handler value we can inhert from before exec is SIG_IGN
435+
// (any actual function pointer is reset to SIG_DFL during exec).
436+
// If that's the case, we want to reset it back to SIG_DFL.
437+
// However, it's also possible that an embeder (or an LD_PRELOAD-ed
438+
// library) has set up own signal handler for own purposes
439+
// (e.g. profiling). If that's the case, we want to keep it intact.
440+
struct sigaction old;
441+
CHECK_EQ(0, sigaction(nr, nullptr, &old));
442+
if ((old.sa_flags & SA_SIGINFO) || old.sa_handler != SIG_IGN)
443+
continue;
444+
}
433445
CHECK_EQ(0, sigaction(nr, &act, nullptr));
434446
}
435447
#endif // __POSIX__

0 commit comments

Comments
 (0)