diff --git a/src/node.cc b/src/node.cc index ada2c957e4..fbffc626d4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -187,6 +187,7 @@ static v8::Platform* default_platform; #ifdef __POSIX__ static uv_sem_t debug_semaphore; +static const unsigned kMaxSignal = 32; #endif static void PrintErrorString(const char* format, ...) { @@ -2095,7 +2096,29 @@ static void InitGroups(const FunctionCallbackInfo& args) { #endif // __POSIX__ && !defined(__ANDROID__) +static void WaitForInspectorDisconnect(Environment* env) { +#if HAVE_INSPECTOR + if (env->inspector_agent()->IsConnected()) { + // Restore signal dispositions, the app is done and is no longer + // capable of handling signals. +#ifdef __POSIX__ + struct sigaction act; + memset(&act, 0, sizeof(act)); + for (unsigned nr = 1; nr < kMaxSignal; nr += 1) { + if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF) + continue; + act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL; + CHECK_EQ(0, sigaction(nr, &act, nullptr)); + } +#endif + env->inspector_agent()->WaitForDisconnect(); + } +#endif +} + + void Exit(const FunctionCallbackInfo& args) { + WaitForInspectorDisconnect(Environment::GetCurrent(args)); exit(args[0]->Int32Value()); } @@ -3992,7 +4015,7 @@ inline void PlatformInit() { // The hard-coded upper limit is because NSIG is not very reliable; on Linux, // it evaluates to 32, 34 or 64, depending on whether RT signals are enabled. // Counting up to SIGRTMIN doesn't work for the same reason. - for (unsigned nr = 1; nr < 32; nr += 1) { + for (unsigned nr = 1; nr < kMaxSignal; nr += 1) { if (nr == SIGKILL || nr == SIGSTOP) continue; act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL; @@ -4302,24 +4325,7 @@ static void StartNodeInstance(void* arg) { instance_data->set_exit_code(exit_code); RunAtExit(&env); -#if HAVE_INSPECTOR - if (env.inspector_agent()->IsConnected()) { - // Restore signal dispositions, the app is done and is no longer - // capable of handling signals. -#ifdef __POSIX__ - struct sigaction act; - memset(&act, 0, sizeof(act)); - for (unsigned nr = 1; nr < 32; nr += 1) { - if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF) - continue; - act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL; - CHECK_EQ(0, sigaction(nr, &act, nullptr)); - } -#endif - env.inspector_agent()->WaitForDisconnect(); - } -#endif - + WaitForInspectorDisconnect(&env); #if defined(LEAK_SANITIZER) __lsan_do_leak_check(); #endif