Skip to content

Commit 61fe1fe

Browse files
indutnyJulien Gilli
authored and
Julien Gilli
committed
src: backport fix for SIGINT crash on FreeBSD
This is a backport of b64983d. Original commit message: 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 <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Fixes #9326. Reviewed-By: Trevor Norris <[email protected]> PR-URL: nodejs/node-v0.x-archive#14184
1 parent d6484f3 commit 61fe1fe

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
@@ -2785,6 +2785,13 @@ static void AtExit() {
27852785

27862786
static void SignalExit(int signo) {
27872787
uv_tty_reset_mode();
2788+
#ifdef __FreeBSD__
2789+
// FreeBSD has a nasty bug, see RegisterSignalHandler for details
2790+
struct sigaction sa;
2791+
memset(&sa, 0, sizeof(sa));
2792+
sa.sa_handler = SIG_DFL;
2793+
CHECK_EQ(sigaction(signo, &sa, nullptr), 0);
2794+
#endif
27882795
raise(signo);
27892796
}
27902797

@@ -3163,7 +3170,12 @@ static void RegisterSignalHandler(int signal,
31633170
struct sigaction sa;
31643171
memset(&sa, 0, sizeof(sa));
31653172
sa.sa_handler = handler;
3173+
#ifndef __FreeBSD__
3174+
// FreeBSD has a nasty bug with SA_RESETHAND reseting the SA_SIGINFO, that is
3175+
// in turn set for a libthr wrapper. This leads to a crash.
3176+
// Work around the issue by manually setting SIG_DFL in the signal handler
31663177
sa.sa_flags = reset_handler ? SA_RESETHAND : 0;
3178+
#endif
31673179
sigfillset(&sa.sa_mask);
31683180
CHECK_EQ(sigaction(signal, &sa, NULL), 0);
31693181
}
+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)