Skip to content

Commit 25f4495

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

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/inspector_agent.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ static int StartDebugSignalHandler() {
125125
pthread_t thread;
126126
const int err = pthread_create(&thread, &attr,
127127
StartIoThreadMain, nullptr);
128-
// Restore original mask
129-
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
130128
CHECK_EQ(0, pthread_attr_destroy(&attr));
131129
if (err != 0) {
130+
// Restore original mask
131+
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
132132
fprintf(stderr, "node[%u]: pthread_create: %s\n",
133133
uv_os_getpid(), strerror(err));
134134
fflush(stderr);
@@ -137,6 +137,8 @@ static int StartDebugSignalHandler() {
137137
return -err;
138138
}
139139
RegisterSignalHandler(SIGUSR1, StartIoThreadWakeup);
140+
// Restore original mask
141+
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
140142
// Unblock SIGUSR1. A pending SIGUSR1 signal will now be delivered.
141143
sigemptyset(&sigmask);
142144
sigaddset(&sigmask, SIGUSR1);

src/node_watchdog.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,11 @@ 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+
});
315+
312316
if (ret != 0) {
313317
return ret;
314318
}

0 commit comments

Comments
 (0)