mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-23 11:43:26 +00:00
1. Fixed bug with process.cwd() on windows when the cwd is a root level folder
2. Added process.chdir() 3. Updated child_process._execve() to use process.env if not specified 4. Updated service manager to work better with docker container
This commit is contained in:
@@ -552,6 +552,25 @@ duk_ret_t ILibDuktape_ChildProcess_execve(duk_context *ctx)
|
||||
WCHAR* wtmp;
|
||||
#endif
|
||||
|
||||
if (nargs < 3 || !(duk_is_object(ctx, 2) && duk_has_prop_string(ctx, 2, "env")))
|
||||
{
|
||||
duk_push_this(ctx); // [childprocess]
|
||||
duk_prepare_method_call(ctx, -1, "_execve"); // [childprocess][execve][this]
|
||||
duk_dup(ctx, 0); duk_dup(ctx, 1); // [childprocess][execve][this][path][parms]
|
||||
if (nargs > 2 && duk_is_object(ctx, 2))
|
||||
{
|
||||
duk_dup(ctx, 2); // [childprocess][execve][this][path][parms][options]
|
||||
}
|
||||
else
|
||||
{
|
||||
duk_push_object(ctx); // [childprocess][execve][this][path][parms][options]
|
||||
}
|
||||
duk_eval_string(ctx, "process.env"); // [childprocess][execve][this][path][parms][options][env]
|
||||
duk_put_prop_string(ctx, -2, "env"); // [childprocess][execve][this][path][parms][options]
|
||||
duk_call_method(ctx, 3);
|
||||
return(ILibDuktape_Error(ctx, "execve() error"));
|
||||
}
|
||||
|
||||
duk_push_array(ctx); // [WCHAR_ARRAY]
|
||||
args = (void**)ILibMemory_SmartAllocate(sizeof(char*) * (1 + duk_get_length(ctx, 1)));
|
||||
for (i = 0; i < (int)duk_get_length(ctx, 1); ++i)
|
||||
@@ -566,10 +585,9 @@ duk_ret_t ILibDuktape_ChildProcess_execve(duk_context *ctx)
|
||||
#endif
|
||||
duk_pop(ctx); // [WCHAR_ARRAY]
|
||||
}
|
||||
|
||||
if (nargs > 2 && duk_is_object(ctx, 2) && duk_has_prop_string(ctx, 2, "env"))
|
||||
{
|
||||
duk_get_prop_string(ctx, 2, "env"); // [WCHAR_ARRAY][obj]
|
||||
duk_get_prop_string(ctx, 2, "env"); // [WCHAR_ARRAY][obj]
|
||||
|
||||
duk_push_array(ctx); // [WCHAR_ARRAY][obj][array]
|
||||
duk_enum(ctx, -2, DUK_ENUM_OWN_PROPERTIES_ONLY); // [WCHAR_ARRAY][obj][array][enum]
|
||||
@@ -601,13 +619,17 @@ duk_ret_t ILibDuktape_ChildProcess_execve(duk_context *ctx)
|
||||
//
|
||||
// We must close all open descriptors first, since the "new" process will have no idea about any that are still open
|
||||
//
|
||||
duk_eval_string(ctx, "require('util-descriptors').getOpenDescriptors();"); // [array]
|
||||
while (duk_get_length(ctx, -1) > 0)
|
||||
if (nargs > 2 && duk_is_object(ctx, 2) && Duktape_GetBooleanProperty(ctx, 2, "close", 1) != 0)
|
||||
{
|
||||
duk_array_pop(ctx, -1); // [array][fd]
|
||||
close(duk_get_int(ctx, -1)); duk_pop(ctx); // [array]
|
||||
int d;
|
||||
duk_eval_string(ctx, "require('util-descriptors').getOpenDescriptors();"); // [array]
|
||||
while (duk_get_length(ctx, -1) > 0)
|
||||
{
|
||||
duk_array_pop(ctx, -1); // [array][fd]
|
||||
d = duk_get_int(ctx, -1); duk_pop(ctx); // [array]
|
||||
if (d > 2) { close(d); } // [array]
|
||||
}
|
||||
}
|
||||
|
||||
execve(path, (char**)args, (char**)env);
|
||||
return(ILibDuktape_Error(ctx, "_execve() returned error: %d ", errno));
|
||||
#else
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -21,6 +21,7 @@ limitations under the License.
|
||||
#include <Windows.h>
|
||||
#include <WinBase.h>
|
||||
#include <signal.h>
|
||||
#include <direct.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -890,7 +891,16 @@ duk_ret_t ILibDuktape_Process_cwd(duk_context *ctx)
|
||||
duk_get_prop_string(ctx, -1, "concat"); // [string][concat]
|
||||
duk_swap_top(ctx, -2); // [concat][this]
|
||||
#ifdef WIN32
|
||||
duk_push_string(ctx, "\\");
|
||||
duk_string_endsWith(ctx, -1, "\\"); // [concat][this][bool]
|
||||
if (!duk_get_boolean(ctx, -1))
|
||||
{
|
||||
duk_push_string(ctx, "\\"); // [concat][this][bool][/]
|
||||
}
|
||||
else
|
||||
{
|
||||
duk_push_string(ctx, "");
|
||||
}
|
||||
duk_remove(ctx, -2); // [concat][this][/]
|
||||
#else
|
||||
duk_push_string(ctx, "/");
|
||||
#endif
|
||||
@@ -1196,6 +1206,17 @@ duk_ret_t ILibDuktape_Process_SignalHooks(duk_context *ctx)
|
||||
return(0);
|
||||
}
|
||||
|
||||
duk_ret_t ILibDuktape_Process_chdir(duk_context *ctx)
|
||||
{
|
||||
char *path = (char*)duk_require_string(ctx, 0);
|
||||
#ifdef WIN32
|
||||
if (_wchdir(ILibUTF8ToWide(path, -1)) != 0) { return(ILibDuktape_Error(ctx, "chdir() failed")); }
|
||||
#else
|
||||
if (chdir(path) != 0) { return(ILibDuktape_Error(ctx, "chdir() failed")); }
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
void ILibDuktape_ScriptContainer_Process_Init(duk_context *ctx, char **argList)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -1210,6 +1231,7 @@ void ILibDuktape_ScriptContainer_Process_Init(duk_context *ctx, char **argList)
|
||||
ILibDuktape_WriteID(ctx, "process");
|
||||
ILibDuktape_CreateEventWithGetter(ctx, "env", ILibDuktape_ScriptContainer_Process_env);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "cwd", ILibDuktape_Process_cwd, 0);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "chdir", ILibDuktape_Process_chdir, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "setenv", ILibDuktape_Process_setenv, 2);
|
||||
ILibDuktape_CreateEventWithSetterEx(ctx, "_SemaphoreTracking", ILibDuktape_Process_SemaphoreTracking);
|
||||
ILibDuktape_CreateEventWithGetterAndSetterEx(ctx, "coreDumpLocation", ILibDuktape_ScriptContainer_Process_coreDumpLocation_getter, ILibDuktape_ScriptContainer_Process_coreDumpLocation_setter);
|
||||
|
||||
Reference in New Issue
Block a user