From 8c11d7455048f9a1584e8c470fe1079799f2b8d8 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 19 Mar 2015 22:03:34 -0700 Subject: [PATCH 1/6] node: 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: https://github.com/joyent/node/issues/9326 --- src/node.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/node.cc b/src/node.cc index 42b690f5d41b72..289336aef4f9a1 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2877,6 +2877,14 @@ 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; + sigfillset(&sa.sa_mask); + CHECK_EQ(sigaction(signo, &sa, nullptr), 0); +#endif raise(signo); } @@ -3257,7 +3265,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, nullptr), 0); } From 9d5004908adfb7e698825ff34e8281d810f3ef2a Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 19 Mar 2015 22:08:35 -0700 Subject: [PATCH 2/6] add test --- test/parallel/test-regress-gh-node-9326 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/parallel/test-regress-gh-node-9326 diff --git a/test/parallel/test-regress-gh-node-9326 b/test/parallel/test-regress-gh-node-9326 new file mode 100644 index 00000000000000..91ad0d10205a93 --- /dev/null +++ b/test/parallel/test-regress-gh-node-9326 @@ -0,0 +1,2 @@ +// NOTE: Was crashing on FreeBSD +process.kill(process.pid, 'SIGINT'); From a273745205458b601b7149be32c633ab5c68dfdd Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 20 Mar 2015 09:22:08 -0700 Subject: [PATCH 3/6] ... --- .../{test-regress-gh-node-9326 => test-regress-gh-node-9326.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/parallel/{test-regress-gh-node-9326 => test-regress-gh-node-9326.js} (100%) diff --git a/test/parallel/test-regress-gh-node-9326 b/test/parallel/test-regress-gh-node-9326.js similarity index 100% rename from test/parallel/test-regress-gh-node-9326 rename to test/parallel/test-regress-gh-node-9326.js From 45bf9b6cd5b4af58c62b16c9b79f5f6e25609cac Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 20 Mar 2015 09:23:10 -0700 Subject: [PATCH 4/6] ... --- src/node.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 289336aef4f9a1..b8decf8c3975bb 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2882,7 +2882,6 @@ static void SignalExit(int signo) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_DFL; - sigfillset(&sa.sa_mask); CHECK_EQ(sigaction(signo, &sa, nullptr), 0); #endif raise(signo); From ee586e53282a3388e6257c69ee0c0d8bacb90817 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 20 Mar 2015 09:54:37 -0700 Subject: [PATCH 5/6] ... --- test/parallel/test-regress-gh-node-9326.js | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 test/parallel/test-regress-gh-node-9326.js diff --git a/test/parallel/test-regress-gh-node-9326.js b/test/parallel/test-regress-gh-node-9326.js deleted file mode 100644 index 91ad0d10205a93..00000000000000 --- a/test/parallel/test-regress-gh-node-9326.js +++ /dev/null @@ -1,2 +0,0 @@ -// NOTE: Was crashing on FreeBSD -process.kill(process.pid, 'SIGINT'); From 8ce3971dcaaf939da0817415284a4a521889664b Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 20 Mar 2015 09:57:07 -0700 Subject: [PATCH 6/6] ... --- test/parallel/test-regress-GH-node-9326.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/parallel/test-regress-GH-node-9326.js diff --git a/test/parallel/test-regress-GH-node-9326.js b/test/parallel/test-regress-GH-node-9326.js new file mode 100644 index 00000000000000..15a2abbdc55af0 --- /dev/null +++ b/test/parallel/test-regress-GH-node-9326.js @@ -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); +});