diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-06-16 20:10:20 +0800 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-06-19 05:25:34 +0200 |
commit | ac1239eaf82c44be96d3865e82df04328dbdf4c0 (patch) | |
tree | b77f89c2fa04ae8622f3c37ad72934f23f4f67d0 /src/inspector_profiler.cc | |
parent | 26bd0dfc1b3c11ba9f0562b657b8b58333b2c459 (diff) | |
download | node-new-ac1239eaf82c44be96d3865e82df04328dbdf4c0.tar.gz |
src: fall back to env->exec_path() for default profile directory
When the current working directory is deleted, fall back to
exec_path as the default profile directory.
PR-URL: https://github.com/nodejs/node/pull/28252
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_profiler.cc')
-rw-r--r-- | src/inspector_profiler.cc | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/inspector_profiler.cc b/src/inspector_profiler.cc index 1b20398dba..122118324f 100644 --- a/src/inspector_profiler.cc +++ b/src/inspector_profiler.cc @@ -320,17 +320,20 @@ void EndStartedProfilers(Environment* env) { } } -std::string GetCwd() { +std::string GetCwd(Environment* env) { char cwd[PATH_MAX_BYTES]; size_t size = PATH_MAX_BYTES; int err = uv_cwd(cwd, &size); - // This can fail if the cwd is deleted. - // TODO(joyeecheung): store this in the Environment during Environment - // creation and fallback to exec_path and argv0, then we no longer need - // SetCoverageDirectory(). - CHECK_EQ(err, 0); - CHECK_GT(size, 0); - return cwd; + + if (err == 0) { + CHECK_GT(size, 0); + return cwd; + } + + // This can fail if the cwd is deleted. In that case, fall back to + // exec_path. + const std::string& exec_path = env->exec_path(); + return exec_path.substr(0, exec_path.find_last_of(kPathSeparator)); } void StartProfilers(Environment* env) { @@ -345,7 +348,7 @@ void StartProfilers(Environment* env) { if (env->options()->cpu_prof) { const std::string& dir = env->options()->cpu_prof_dir; env->set_cpu_prof_interval(env->options()->cpu_prof_interval); - env->set_cpu_prof_dir(dir.empty() ? GetCwd() : dir); + env->set_cpu_prof_dir(dir.empty() ? GetCwd(env) : dir); if (env->options()->cpu_prof_name.empty()) { DiagnosticFilename filename(env, "CPU", "cpuprofile"); env->set_cpu_prof_name(*filename); @@ -360,7 +363,7 @@ void StartProfilers(Environment* env) { if (env->options()->heap_prof) { const std::string& dir = env->options()->heap_prof_dir; env->set_heap_prof_interval(env->options()->heap_prof_interval); - env->set_heap_prof_dir(dir.empty() ? GetCwd() : dir); + env->set_heap_prof_dir(dir.empty() ? GetCwd(env) : dir); if (env->options()->heap_prof_name.empty()) { DiagnosticFilename filename(env, "Heap", "heapprofile"); env->set_heap_prof_name(*filename); |