Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-06-16 15:09:42 +0300
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-06-19 06:25:24 +0300
commit26bd0dfc1b3c11ba9f0562b657b8b58333b2c459 (patch)
tree8cee798228b60c81be43d9b4c85dcf86dcd8195c /src/env.cc
parent17a5eba6c271c5faa89bd8a6434cad150aeeb98e (diff)
src: save exec path when initializing Environment
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/env.cc')
-rw-r--r--src/env.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc
index f0f4fc30688..9a251a93069 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -261,6 +261,32 @@ void Environment::CreateProperties() {
set_process_object(process_object);
}
+std::string GetExecPath(const std::vector<std::string>& argv) {
+ char exec_path_buf[2 * PATH_MAX];
+ size_t exec_path_len = sizeof(exec_path_buf);
+ std::string exec_path;
+ if (uv_exepath(exec_path_buf, &exec_path_len) == 0) {
+ exec_path = std::string(exec_path_buf, exec_path_len);
+ } else {
+ exec_path = argv[0];
+ }
+
+ // On OpenBSD process.execPath will be relative unless we
+ // get the full path before process.execPath is used.
+#if defined(__OpenBSD__)
+ uv_fs_t req;
+ req.ptr = nullptr;
+ if (0 ==
+ uv_fs_realpath(env->event_loop(), &req, exec_path.c_str(), nullptr)) {
+ CHECK_NOT_NULL(req.ptr);
+ exec_path = std::string(static_cast<char*>(req.ptr));
+ }
+ uv_fs_req_cleanup(&req);
+#endif
+
+ return exec_path;
+}
+
Environment::Environment(IsolateData* isolate_data,
Local<Context> context,
const std::vector<std::string>& args,
@@ -274,6 +300,7 @@ Environment::Environment(IsolateData* isolate_data,
timer_base_(uv_now(isolate_data->event_loop())),
exec_argv_(exec_args),
argv_(args),
+ exec_path_(GetExecPath(args)),
should_abort_on_uncaught_toggle_(isolate_, 1),
stream_base_state_(isolate_, StreamBase::kNumStreamBaseStateFields),
flags_(flags),