Skip to content

Commit

Permalink
src: don't reset embeder signal handlers
Browse files Browse the repository at this point in the history
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 nodejs#47013
  • Loading branch information
dvyukov committed Mar 21, 2023
1 parent 1640aeb commit 07cb9ef
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ void ResetSignalHandlers() {
if (nr == SIGKILL || nr == SIGSTOP)
continue;
act.sa_handler = (nr == SIGPIPE || nr == SIGXFSZ) ? SIG_IGN : SIG_DFL;
if (act.sa_handler == SIG_DFL) {
// 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, we want to keep it intact.
struct sigaction old;
CHECK_EQ(0, sigaction(nr, nullptr, &old));
if ((old.sa_flags & SA_SIGINFO) || old.sa_handler != SIG_IGN)
continue;
}
CHECK_EQ(0, sigaction(nr, &act, nullptr));
}
#endif // __POSIX__
Expand Down

0 comments on commit 07cb9ef

Please sign in to comment.