Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ void Agent::PostMessages() {
dispatching_messages_ = false;
}

bool Agent::IsStarted() {
return !!platform_;
}

static void InterruptCallback(v8::Isolate*, void* agent) {
reinterpret_cast<Agent*>(agent)->PostMessages();
}
Expand Down
1 change: 1 addition & 0 deletions src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Agent {

void PostMessages();

bool IsStarted();
bool connected() { return connected_; }

protected:
Expand Down
27 changes: 19 additions & 8 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4434,21 +4434,32 @@ static void StartNodeInstance(void* arg) {
} while (more == true);
}

#if HAVE_INSPECTOR
if (env->inspector_agent()->connected())
fprintf(stderr, "Waiting for the debugger to disconnect...\n");
while (env->inspector_agent()->connected()) {
v8::platform::PumpMessageLoop(default_platform, isolate);
}
#endif

env->set_trace_sync_io(false);

int exit_code = EmitExit(env);
if (instance_data->is_main())
instance_data->set_exit_code(exit_code);
RunAtExit(env);

#if HAVE_INSPECTOR
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a TODO: add non-POSIX support. I will add this when merging.

if (env->inspector_agent()->connected()) {
// Restore signal dispositions, the app is done and is no longer
// capable of handling signals.
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));
}
fprintf(stderr, "Waiting for the debugger to disconnect...\n");
while (env->inspector_agent()->connected()) {
v8::platform::PumpMessageLoop(default_platform, isolate);
}
}
#endif

#if defined(LEAK_SANITIZER)
__lsan_do_leak_check();
#endif
Expand Down
9 changes: 9 additions & 0 deletions src/signal_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class SignalWrap : public HandleWrap {
static void Start(const FunctionCallbackInfo<Value>& args) {
SignalWrap* wrap = Unwrap<SignalWrap>(args.Holder());
int signum = args[0]->Int32Value();
#if HAVE_INSPECTOR
if (signum == SIGPROF) {
Environment* env = Environment::GetCurrent(args);
if (env->inspector_agent()->IsStarted()) {
fprintf(stderr, "process.on(SIGPROF) is reserved while debugging\n");
return;
}
}
#endif
int err = uv_signal_start(&wrap->handle_, OnSignal, signum);
args.GetReturnValue().Set(err);
}
Expand Down