Skip to content

Commit

Permalink
src: set SA_SIGINFO flag when using sa_sigaction
Browse files Browse the repository at this point in the history
For `sigaction()` the `SA_SIGINFO` flag should be set when setting
the handler via the `sa_sigaction` member of the `sigaction` struct.
  • Loading branch information
richardlau committed Aug 6, 2020
1 parent 22cbbcf commit 517a93d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void RegisterSignalHandler(int signal,
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = handler;
sa.sa_flags = reset_handler ? SA_RESETHAND : 0;
sa.sa_flags = reset_handler ? SA_RESETHAND | SA_SIGINFO : SA_SIGINFO;
sigfillset(&sa.sa_mask);
CHECK_EQ(sigaction(signal, &sa, nullptr), 0);
}
Expand Down Expand Up @@ -638,6 +638,7 @@ inline void PlatformInit() {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = TrapWebAssemblyOrContinue;
sa.sa_flags = SA_SIGINFO;
CHECK_EQ(sigaction(SIGSEGV, &sa, nullptr), 0);
}
V8::EnableWebAssemblyTrapHandler(false);
Expand Down
1 change: 1 addition & 0 deletions test/addons/register-signal-handler/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using v8::Value;
void Handler(int signo, siginfo_t* siginfo, void* ucontext) {
char signo_char = signo;
int written;
assert(signo == siginfo->si_signo);
do {
written = write(1, &signo_char, 1); // write() is signal-safe.
} while (written == -1 && errno == EINTR);
Expand Down

0 comments on commit 517a93d

Please sign in to comment.