Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
src: backport fix for SIGINT crash on FreeBSD
Browse files Browse the repository at this point in the history
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: #9326
  PR-URL: nodejs/node#1218
  Reviewed-By: Johan Bergström <[email protected]>
  Reviewed-By: Ben Noordhuis <[email protected]>

Fixes #9326.

Reviewed-By: Trevor Norris <[email protected]>
PR-URL: #14184
  • Loading branch information
indutny authored and Julien Gilli committed Mar 28, 2015
1 parent d6484f3 commit 61fe1fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2785,6 +2785,13 @@ static void AtExit() {

static void SignalExit(int signo) {
uv_tty_reset_mode();
#ifdef __FreeBSD__
// FreeBSD has a nasty bug, see RegisterSignalHandler for details
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
CHECK_EQ(sigaction(signo, &sa, nullptr), 0);
#endif
raise(signo);
}

Expand Down Expand Up @@ -3163,7 +3170,12 @@ static void RegisterSignalHandler(int signal,
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
#ifndef __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
sa.sa_flags = reset_handler ? SA_RESETHAND : 0;
#endif
sigfillset(&sa.sa_mask);
CHECK_EQ(sigaction(signal, &sa, NULL), 0);
}
Expand Down
12 changes: 12 additions & 0 deletions test/simple/test-regress-GH-node-9326.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var assert = require('assert');
var child_process = require('child_process');

// NOTE: Was crashing on FreeBSD
var cp = child_process.spawn(process.execPath, [
'-e',
'process.kill(process.pid, "SIGINT")'
]);

cp.on('exit', function(code) {
assert.notEqual(code, 0);
});

0 comments on commit 61fe1fe

Please sign in to comment.