process: normalize process.execPath in CreateProcessObject()
Directly normalize `process.execPath` using `uv_fs_realpath` on OpenBSD before serializing it into the process object, instead of using `require('fs')` to normalize and override the path in `bootstrap/node.js`. PR-URL: https://github.com/nodejs/node/pull/26002 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
9e84a26cb3
commit
af83f6af5d
@ -187,13 +187,6 @@ if (browserGlobals) {
|
|||||||
|
|
||||||
setupDOMException();
|
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', {
|
Object.defineProperty(process, 'argv0', {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: false,
|
configurable: false,
|
||||||
|
@ -273,21 +273,34 @@ MaybeLocal<Object> CreateProcessObject(
|
|||||||
|
|
||||||
// process.execPath
|
// process.execPath
|
||||||
{
|
{
|
||||||
size_t exec_path_len = 2 * PATH_MAX;
|
char exec_path_buf[2 * PATH_MAX];
|
||||||
std::vector<char> exec_path(exec_path_len);
|
size_t exec_path_len = sizeof(exec_path_buf);
|
||||||
Local<String> exec_path_value;
|
std::string exec_path;
|
||||||
if (uv_exepath(exec_path.data(), &exec_path_len) == 0) {
|
if (uv_exepath(exec_path_buf, &exec_path_len) == 0) {
|
||||||
exec_path_value = String::NewFromUtf8(env->isolate(),
|
exec_path = std::string(exec_path_buf, exec_path_len);
|
||||||
exec_path.data(),
|
|
||||||
NewStringType::kInternalized,
|
|
||||||
exec_path_len).ToLocalChecked();
|
|
||||||
} else {
|
} else {
|
||||||
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
|
exec_path = args[0];
|
||||||
NewStringType::kInternalized).ToLocalChecked();
|
|
||||||
}
|
}
|
||||||
process->Set(env->context(),
|
// On OpenBSD process.execPath will be relative unless we
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
|
// get the full path before process.execPath is used.
|
||||||
exec_path_value).FromJust();
|
#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
|
// process.debugPort
|
||||||
|
Loading…
x
Reference in New Issue
Block a user