diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-11-02 21:06:47 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-11-07 01:26:03 +0300 |
commit | 5bf43729a403b992cc90b5cdbbaaf505769d1107 (patch) | |
tree | e0f7eea86af950fdfc8cecaca63a6334d2072159 /src/node_process_methods.cc | |
parent | 55f98df303939774639bb597c6392c1c85bae6dd (diff) |
src: make EndStartedProfilers an exit hook
Run `EndStartedProfilers` on Environment teardown.
This is part of a series of changes to make embedding easier, by
requiring fewer internal methods to build a fully functioning
Node.js instance.
PR-URL: https://github.com/nodejs/node/pull/30229
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Diffstat (limited to 'src/node_process_methods.cc')
-rw-r--r-- | src/node_process_methods.cc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 3a2c1efd812..3f0590aef7f 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -172,11 +172,15 @@ static void Kill(const FunctionCallbackInfo<Value>& args) { if (!args[0]->Int32Value(context).To(&pid)) return; int sig; if (!args[1]->Int32Value(context).To(&sig)) return; - // TODO(joyeecheung): white list the signals? -#if HAVE_INSPECTOR - profiler::EndStartedProfilers(env); -#endif + uv_pid_t own_pid = uv_os_getpid(); + if (sig > 0 && + (pid == 0 || pid == -1 || pid == own_pid || pid == -own_pid) && + !HasSignalJSHandler(sig)) { + // This is most likely going to terminate this process. + // It's not an exact method but it might be close enough. + RunAtExit(env); + } int err = uv_kill(pid, sig); args.GetReturnValue().Set(err); @@ -428,6 +432,7 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args) { static void ReallyExit(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); + RunAtExit(env); WaitForInspectorDisconnect(env); int code = args[0]->Int32Value(env->context()).FromMaybe(0); env->Exit(code); |