Skip to content

Commit a6c462c

Browse files
committed
src: call unmask after install signal handler
1 parent 049664b commit a6c462c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/inspector_agent.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ static int StartDebugSignalHandler() {
123123
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, &savemask));
124124
sigmask = savemask;
125125
pthread_t thread;
126-
const int err = pthread_create(&thread, &attr,
127-
StartIoThreadMain, nullptr);
128-
// Restore original mask
129-
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
126+
const int err = pthread_create(&thread, &attr, StartIoThreadMain, nullptr);
130127
CHECK_EQ(0, pthread_attr_destroy(&attr));
131128
if (err != 0) {
129+
// Restore original mask
130+
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
132131
fprintf(stderr, "node[%u]: pthread_create: %s\n",
133132
uv_os_getpid(), strerror(err));
134133
fflush(stderr);
@@ -137,6 +136,8 @@ static int StartDebugSignalHandler() {
137136
return -err;
138137
}
139138
RegisterSignalHandler(SIGUSR1, StartIoThreadWakeup);
139+
// Restore original mask
140+
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
140141
// Unblock SIGUSR1. A pending SIGUSR1 signal will now be delivered.
141142
sigemptyset(&sigmask);
142143
sigaddset(&sigmask, SIGUSR1);

src/node_watchdog.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ int SigintWatchdogHelper::Start() {
308308
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, &savemask));
309309
sigmask = savemask;
310310
int ret = pthread_create(&thread_, nullptr, RunSigintWatchdog, nullptr);
311-
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
311+
312+
auto cleanup = OnScopeLeave(
313+
[&]() { CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr)); });
314+
312315
if (ret != 0) {
313316
return ret;
314317
}

0 commit comments

Comments
 (0)