@@ -261,6 +261,32 @@ void Environment::CreateProperties() {
261
261
set_process_object (process_object);
262
262
}
263
263
264
+ std::string GetExecPath (const std::vector<std::string>& argv) {
265
+ char exec_path_buf[2 * PATH_MAX];
266
+ size_t exec_path_len = sizeof (exec_path_buf);
267
+ std::string exec_path;
268
+ if (uv_exepath (exec_path_buf, &exec_path_len) == 0 ) {
269
+ exec_path = std::string (exec_path_buf, exec_path_len);
270
+ } else {
271
+ exec_path = argv[0 ];
272
+ }
273
+
274
+ // On OpenBSD process.execPath will be relative unless we
275
+ // get the full path before process.execPath is used.
276
+ #if defined(__OpenBSD__)
277
+ uv_fs_t req;
278
+ req.ptr = nullptr ;
279
+ if (0 ==
280
+ uv_fs_realpath (env->event_loop (), &req, exec_path.c_str (), nullptr )) {
281
+ CHECK_NOT_NULL (req.ptr );
282
+ exec_path = std::string (static_cast <char *>(req.ptr ));
283
+ }
284
+ uv_fs_req_cleanup (&req);
285
+ #endif
286
+
287
+ return exec_path;
288
+ }
289
+
264
290
Environment::Environment (IsolateData* isolate_data,
265
291
Local<Context> context,
266
292
const std::vector<std::string>& args,
@@ -274,6 +300,7 @@ Environment::Environment(IsolateData* isolate_data,
274
300
timer_base_(uv_now(isolate_data->event_loop ())),
275
301
exec_argv_(exec_args),
276
302
argv_(args),
303
+ exec_path_(GetExecPath(args)),
277
304
should_abort_on_uncaught_toggle_(isolate_, 1 ),
278
305
stream_base_state_(isolate_, StreamBase::kNumStreamBaseStateFields ),
279
306
flags_(flags),
0 commit comments