Skip to content

Commit b64983d

Browse files
committed
src: reset signal handler to SIG_DFL on FreeBSD
FreeBSD has a nasty bug with SA_RESETHAND reseting the SA_SIGINFO, that is in turn set for a libthr wrapper. This leads to a crash. Work around the issue by manually setting SIG_DFL in the signal handler. Fix: nodejs/node-v0.x-archive#9326 PR-URL: #1218 Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 6fc5e95 commit b64983d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/node.cc

+12
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,13 @@ static void AtExit() {
28772877

28782878
static void SignalExit(int signo) {
28792879
uv_tty_reset_mode();
2880+
#ifdef __FreeBSD__
2881+
// FreeBSD has a nasty bug, see RegisterSignalHandler for details
2882+
struct sigaction sa;
2883+
memset(&sa, 0, sizeof(sa));
2884+
sa.sa_handler = SIG_DFL;
2885+
CHECK_EQ(sigaction(signo, &sa, nullptr), 0);
2886+
#endif
28802887
raise(signo);
28812888
}
28822889

@@ -3257,7 +3264,12 @@ static void RegisterSignalHandler(int signal,
32573264
struct sigaction sa;
32583265
memset(&sa, 0, sizeof(sa));
32593266
sa.sa_handler = handler;
3267+
#ifndef __FreeBSD__
3268+
// FreeBSD has a nasty bug with SA_RESETHAND reseting the SA_SIGINFO, that is
3269+
// in turn set for a libthr wrapper. This leads to a crash.
3270+
// Work around the issue by manually setting SIG_DFL in the signal handler
32603271
sa.sa_flags = reset_handler ? SA_RESETHAND : 0;
3272+
#endif
32613273
sigfillset(&sa.sa_mask);
32623274
CHECK_EQ(sigaction(signal, &sa, nullptr), 0);
32633275
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var assert = require('assert');
2+
var child_process = require('child_process');
3+
4+
// NOTE: Was crashing on FreeBSD
5+
var cp = child_process.spawn(process.execPath, [
6+
'-e',
7+
'process.kill(process.pid, "SIGINT")'
8+
]);
9+
10+
cp.on('exit', function(code) {
11+
assert.notEqual(code, 0);
12+
});

0 commit comments

Comments
 (0)