Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: normalize process.execPath in CreateProcessObject() #26002

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,6 @@ if (browserGlobals) {

setupDOMException();

// On OpenBSD process.execPath will be relative unless we
// get the full path before process.execPath is used.
if (process.platform === 'openbsd') {
const { realpathSync } = NativeModule.require('fs');
process.execPath = realpathSync.native(process.execPath);
}

Object.defineProperty(process, 'argv0', {
enumerable: true,
configurable: false,
Expand Down
39 changes: 26 additions & 13 deletions src/node_process_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,34 @@ MaybeLocal<Object> CreateProcessObject(

// process.execPath
{
size_t exec_path_len = 2 * PATH_MAX;
std::vector<char> exec_path(exec_path_len);
Local<String> exec_path_value;
if (uv_exepath(exec_path.data(), &exec_path_len) == 0) {
exec_path_value = String::NewFromUtf8(env->isolate(),
exec_path.data(),
NewStringType::kInternalized,
exec_path_len).ToLocalChecked();
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_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
NewStringType::kInternalized).ToLocalChecked();
exec_path = args[0];
}
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value).FromJust();
// 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));
}
#endif
process
->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
String::NewFromUtf8(env->isolate(),
exec_path.c_str(),
NewStringType::kInternalized,
exec_path.size())
.ToLocalChecked())
.FromJust();
}

// process.debugPort
Expand Down