@@ -188,6 +188,7 @@ static v8::Platform* default_platform;
188188
189189#ifdef __POSIX__
190190static uv_sem_t debug_semaphore;
191+ static const unsigned kMaxSignal = 32 ;
191192#endif
192193
193194static void PrintErrorString (const char * format, ...) {
@@ -2149,7 +2150,29 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {
21492150#endif // __POSIX__ && !defined(__ANDROID__)
21502151
21512152
2153+ static void WaitForInspectorDisconnect (Environment* env) {
2154+ #if HAVE_INSPECTOR
2155+ if (env->inspector_agent ()->IsConnected ()) {
2156+ // Restore signal dispositions, the app is done and is no longer
2157+ // capable of handling signals.
2158+ #ifdef __POSIX__
2159+ struct sigaction act;
2160+ memset (&act, 0 , sizeof (act));
2161+ for (unsigned nr = 1 ; nr < kMaxSignal ; nr += 1 ) {
2162+ if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF)
2163+ continue ;
2164+ act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
2165+ CHECK_EQ (0 , sigaction (nr, &act, nullptr ));
2166+ }
2167+ #endif
2168+ env->inspector_agent ()->WaitForDisconnect ();
2169+ }
2170+ #endif
2171+ }
2172+
2173+
21522174void Exit (const FunctionCallbackInfo<Value>& args) {
2175+ WaitForInspectorDisconnect (Environment::GetCurrent (args));
21532176 exit (args[0 ]->Int32Value ());
21542177}
21552178
@@ -4076,7 +4099,7 @@ inline void PlatformInit() {
40764099 // The hard-coded upper limit is because NSIG is not very reliable; on Linux,
40774100 // it evaluates to 32, 34 or 64, depending on whether RT signals are enabled.
40784101 // Counting up to SIGRTMIN doesn't work for the same reason.
4079- for (unsigned nr = 1 ; nr < 32 ; nr += 1 ) {
4102+ for (unsigned nr = 1 ; nr < kMaxSignal ; nr += 1 ) {
40804103 if (nr == SIGKILL || nr == SIGSTOP)
40814104 continue ;
40824105 act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
@@ -4470,24 +4493,7 @@ static void StartNodeInstance(void* arg) {
44704493 instance_data->set_exit_code (exit_code);
44714494 RunAtExit (env);
44724495
4473- #if HAVE_INSPECTOR
4474- if (env->inspector_agent ()->IsConnected ()) {
4475- // Restore signal dispositions, the app is done and is no longer
4476- // capable of handling signals.
4477- #ifdef __POSIX__
4478- struct sigaction act;
4479- memset (&act, 0 , sizeof (act));
4480- for (unsigned nr = 1 ; nr < 32 ; nr += 1 ) {
4481- if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF)
4482- continue ;
4483- act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
4484- CHECK_EQ (0 , sigaction (nr, &act, nullptr ));
4485- }
4486- #endif
4487- env->inspector_agent ()->WaitForDisconnect ();
4488- }
4489- #endif
4490-
4496+ WaitForInspectorDisconnect (env);
44914497#if defined(LEAK_SANITIZER)
44924498 __lsan_do_leak_check ();
44934499#endif
0 commit comments