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>

 Conflicts:
	src/node.cc
  • Loading branch information
Eugene Ostroukhov authored and Fishrock123 committed Jul 5, 2016
1 parent 38d36e3 commit 88b2aa3
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 @@ -188,6 +188,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 @@ -2149,7 +2150,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 @@ -4076,7 +4099,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 @@ -4470,24 +4493,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 88b2aa3

Please sign in to comment.