diff --git a/src/node.cc b/src/node.cc index c8dfe041214f..f0590d5a72bf 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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); } @@ -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); }