summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-06-16 20:10:20 +0800
committerMichaƫl Zasso <targos@protonmail.com>2019-07-02 09:07:41 +0200
commitc491e4dfe6b2af972ec935524af0e0f0eee894b8 (patch)
treead46f7b95932d9ca00581202fe4f458bacedbb72 /src
parent040b9db07be34de306f19df4074a9238c8693e19 (diff)
downloadandroid-node-v8-c491e4dfe6b2af972ec935524af0e0f0eee894b8.tar.gz
android-node-v8-c491e4dfe6b2af972ec935524af0e0f0eee894b8.tar.bz2
android-node-v8-c491e4dfe6b2af972ec935524af0e0f0eee894b8.zip
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')
-rw-r--r--src/inspector_profiler.cc23
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);