Skip to content

Commit

Permalink
inspector: process.exit should wait for inspector
Browse files Browse the repository at this point in the history
Fixes: #7088
PR-URL: #7252
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
Eugene Ostroukhov authored and ofrobots committed Jun 13, 2016
1 parent 0e9e149 commit 6626919
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down Expand Up @@ -2095,7 +2096,29 @@ static void InitGroups(const FunctionCallbackInfo<Value>& 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<Value>& args) {
WaitForInspectorDisconnect(Environment::GetCurrent(args));
exit(args[0]->Int32Value());
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6626919

Please sign in to comment.