mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: set default signal dispositions at start-up
Signal dispositions are inherited by child processes. Restore ours to sane defaults in case our parent process changed it, to prevent quirky behavior when the parent does something silly like ignoring SIGSEGV. PR-URL: https://github.com/iojs/io.js/pull/615 Reviewed-By: Sam Roberts <sam@strongloop.com>
This commit is contained in:
17
src/node.cc
17
src/node.cc
@@ -3313,9 +3313,24 @@ inline void PlatformInit() {
|
||||
sigemptyset(&sigmask);
|
||||
sigaddset(&sigmask, SIGUSR1);
|
||||
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
|
||||
RegisterSignalHandler(SIGPIPE, SIG_IGN);
|
||||
|
||||
// Restore signal dispositions, the parent process may have changed them.
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
|
||||
// The hard-coded upper limit is because NSIG is not very reliable; on Linux,
|
||||
// it evaluates to 32, 34 or 64, depending on whether RT signals are enabled.
|
||||
// Counting up to SIGRTMIN doesn't work for the same reason.
|
||||
for (unsigned nr = 1; nr < 32; nr += 1) {
|
||||
if (nr == SIGKILL || nr == SIGSTOP)
|
||||
continue;
|
||||
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
|
||||
CHECK_EQ(0, sigaction(nr, &act, nullptr));
|
||||
}
|
||||
|
||||
RegisterSignalHandler(SIGINT, SignalExit, true);
|
||||
RegisterSignalHandler(SIGTERM, SignalExit, true);
|
||||
|
||||
// Raise the open file descriptor limit.
|
||||
struct rlimit lim;
|
||||
if (getrlimit(RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max) {
|
||||
|
||||
Reference in New Issue
Block a user