mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-16 08:13:30 +00:00
1. Updated environment variables, so that string values are coerced
2. Added ability to specify termios struct values via environment variables
This commit is contained in:
@@ -366,7 +366,7 @@ duk_ret_t ILibDuktape_ChildProcess_execFile(duk_context *ctx)
|
||||
{
|
||||
|
||||
envargs[ecount] = (char*)duk_get_string(ctx, -2);
|
||||
envargs[ecount + 1] = (char*)duk_get_string(ctx, -1);
|
||||
envargs[ecount + 1] = (char*)duk_to_string(ctx, -1);
|
||||
ecount += 2;
|
||||
duk_pop_2(ctx); // [buf][env][enum]
|
||||
}
|
||||
@@ -428,6 +428,12 @@ void ILibDuktape_ChildProcess_PUSH(duk_context *ctx, void *chain)
|
||||
duk_push_int(ctx, 4);
|
||||
duk_put_prop_string(ctx, -2, "DETACHED");
|
||||
duk_put_prop_string(ctx, -2, "SpawnTypes");
|
||||
|
||||
char flags[] = "exports.c_iflags = {'IGNBRK': 01, 'BRKINT': 02, 'IGNPAR': 04, 'PARMRK': 010,'INPCK': 020, 'ISTRIP': 040, 'INLCR': 0100, 'IGNCR': 0200, 'ICRNL': 0400, 'IUCLC': 01000, 'IXON': 02000, 'IXANY': 04000, 'IXOFF': 010000, 'IMAXBEL': 020000};\
|
||||
exports.c_oflags = {'OPOST': 001, 'OLCUC': 002, 'ONLCR': 004, 'OCRNL': 010, 'ONOCR': 020, 'ONLRET': 040, 'OFILL': 0100, 'OFDEL': 0200};\
|
||||
exports.c_lflags = {'ISIG': 001, 'ICANON': 002, 'ECHO': 010, 'ECHOE': 020, 'ECHOK': 040, 'ECHONL': 0100, 'NOFLSH': 0200, 'IEXTEN': 0400, 'TOSTOP': 0100000, 'ITOSTOP': 0100000}\
|
||||
";
|
||||
ILibDuktape_ModSearch_AddHandler_AlsoIncludeJS(ctx, flags, sizeof(flags) - 1);
|
||||
}
|
||||
void ILibDuktape_ChildProcess_Init(duk_context *ctx)
|
||||
{
|
||||
|
||||
@@ -887,7 +887,6 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
CloseHandle(retVal->stdErr->mPipe_WriteEnd); retVal->stdErr->mPipe_WriteEnd = NULL;
|
||||
CloseHandle(retVal->stdIn->mPipe_ReadEnd); retVal->stdIn->mPipe_ReadEnd = NULL;
|
||||
}
|
||||
|
||||
retVal->hProcess = processInfo.hProcess;
|
||||
if (processInfo.hThread != NULL) CloseHandle(processInfo.hThread);
|
||||
retVal->PID = processInfo.dwProcessId;
|
||||
@@ -904,11 +903,54 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
#ifndef __APPLE__
|
||||
int pipe;
|
||||
struct winsize w;
|
||||
struct termios tios;
|
||||
char **options = (char**)envvars;
|
||||
int flags = 0;
|
||||
memset(&tios, 0, sizeof(tios));
|
||||
|
||||
w.ws_row = CONSOLE_SCREEN_HEIGHT;
|
||||
w.ws_col = CONSOLE_SCREEN_WIDTH;
|
||||
w.ws_xpixel = 0;
|
||||
w.ws_ypixel = 0;
|
||||
pid = forkpty(&pipe, NULL, NULL, &w);
|
||||
|
||||
|
||||
while (options != NULL && options[0] != NULL)
|
||||
{
|
||||
if (strcasecmp("LINES", options[0]) == 0)
|
||||
{
|
||||
w.ws_row = atoi(options[1]);
|
||||
}
|
||||
else if (strcasecmp("COLUMNS", options[0]) == 0)
|
||||
{
|
||||
w.ws_col = atoi(options[1]);
|
||||
}
|
||||
else if (strcasecmp("c_iflag", options[0]) == 0)
|
||||
{
|
||||
flags = 1;
|
||||
tios.c_iflag = (tcflag_t)atoi(options[1]);
|
||||
}
|
||||
else if (strcasecmp("c_oflag", options[0]) == 0)
|
||||
{
|
||||
flags = 1;
|
||||
tios.c_oflag = (tcflag_t)atoi(options[1]);
|
||||
}
|
||||
else if (strcasecmp("c_cflag", options[0]) == 0)
|
||||
{
|
||||
flags = 1;
|
||||
tios.c_cflag = (tcflag_t)atoi(options[1]);
|
||||
}
|
||||
else if (strcasecmp("c_lflag", options[0]) == 0)
|
||||
{
|
||||
flags = 1;
|
||||
tios.c_lflag = (tcflag_t)atoi(options[1]);
|
||||
}
|
||||
|
||||
options += 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pid = forkpty(&pipe, NULL, flags == 0 ? NULL : &tios, &w);
|
||||
retVal->PTY = pipe;
|
||||
retVal->stdIn = ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(pipeManager, pipe, extraMemorySize);
|
||||
retVal->stdOut = ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(pipeManager, pipe, extraMemorySize);
|
||||
|
||||
Reference in New Issue
Block a user