Skip to content

Commit 0769e5a

Browse files
theanarkhaduh95
authored andcommitted
src: call unmask after install signal handler
PR-URL: #59059 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f9bc257 commit 0769e5a

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
@@ -122,12 +122,11 @@ static int StartDebugSignalHandler() {
122122
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, &savemask));
123123
sigmask = savemask;
124124
pthread_t thread;
125-
const int err = pthread_create(&thread, &attr,
126-
StartIoThreadMain, nullptr);
127-
// Restore original mask
128-
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
125+
const int err = pthread_create(&thread, &attr, StartIoThreadMain, nullptr);
129126
CHECK_EQ(0, pthread_attr_destroy(&attr));
130127
if (err != 0) {
128+
// Restore original mask
129+
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
131130
fprintf(stderr, "node[%u]: pthread_create: %s\n",
132131
uv_os_getpid(), strerror(err));
133132
fflush(stderr);
@@ -136,6 +135,8 @@ static int StartDebugSignalHandler() {
136135
return -err;
137136
}
138137
RegisterSignalHandler(SIGUSR1, StartIoThreadWakeup);
138+
// Restore original mask
139+
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
139140
// Unblock SIGUSR1. A pending SIGUSR1 signal will now be delivered.
140141
sigemptyset(&sigmask);
141142
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)