Skip to content

Commit b82360a

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 b82360a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/node.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,17 @@ 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) continue;
443+
}
433444
CHECK_EQ(0, sigaction(nr, &act, nullptr));
434445
}
435446
#endif // __POSIX__

0 commit comments

Comments
 (0)