mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-02-14 23:45:41 +00:00
1. Added pty and tcsetsize to child_process
2. Added ILibProcessPipe_Process_GetPTY to ILibProcessPipe
This commit is contained in:
@@ -193,8 +193,8 @@ duk_ret_t ILibDuktape_ChildProcess_waitExit(duk_context *ctx)
|
||||
}
|
||||
duk_ret_t ILibDuktape_ChildProcess_SpawnedProcess_Finalizer(duk_context *ctx)
|
||||
{
|
||||
ILibDuktape_ChildProcess_SubProcess *retVal = (ILibDuktape_ChildProcess_SubProcess*)Duktape_GetBufferProperty(ctx, 0, ILibDuktape_ChildProcess_MemBuf);
|
||||
#ifdef WIN32
|
||||
ILibDuktape_ChildProcess_SubProcess *retVal = (ILibDuktape_ChildProcess_SubProcess*)Duktape_GetBufferProperty(ctx, 0, ILibDuktape_ChildProcess_MemBuf);
|
||||
ILibProcessPipe_Process_RemoveHandlers(retVal->childProcess);
|
||||
#endif
|
||||
duk_get_prop_string(ctx, 0, "kill"); // [kill]
|
||||
@@ -202,6 +202,27 @@ duk_ret_t ILibDuktape_ChildProcess_SpawnedProcess_Finalizer(duk_context *ctx)
|
||||
duk_call_method(ctx, 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
duk_ret_t ILibDuktape_ChildProcess_tcsetsize(duk_context *ctx)
|
||||
{
|
||||
duk_push_this(ctx);
|
||||
int fd = (int)Duktape_GetIntPropertyValue(ctx, -1, "pty", 0);
|
||||
|
||||
struct winsize ws;
|
||||
ws.ws_row = (int)duk_require_int(ctx, 0);
|
||||
ws.ws_col = (int)duk_require_int(ctx, 1);
|
||||
if (ioctl(fd, TIOCSWINSZ, &ws) == -1)
|
||||
{
|
||||
printf("TIOCSWINSZ FAIL[%d]\n\n", fd);
|
||||
return(ILibDuktape_Error(ctx, "Error making TIOCSWINSZ/IOCTL"));
|
||||
}
|
||||
printf("TIOCSWINSZ[%d] OK\n\n", fd);
|
||||
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
ILibDuktape_ChildProcess_SubProcess* ILibDuktape_ChildProcess_SpawnedProcess_PUSH(duk_context *ctx, ILibProcessPipe_Process mProcess, void *callback)
|
||||
{
|
||||
duk_push_object(ctx); // [ChildProcess]
|
||||
@@ -249,6 +270,14 @@ ILibDuktape_ChildProcess_SubProcess* ILibDuktape_ChildProcess_SpawnedProcess_PUS
|
||||
ILibDuktape_CreateReadonlyProperty(ctx, "parent");
|
||||
retVal->stdIn = ILibDuktape_WritableStream_Init(ctx, ILibDuktape_ChildProcess_SubProcess_StdIn_WriteHandler, ILibDuktape_ChildProcess_SubProcess_StdIn_EndHandler, retVal);
|
||||
ILibDuktape_CreateReadonlyProperty(ctx, "stdin");
|
||||
#ifndef WIN32
|
||||
if (ILibProcessPipe_Process_GetPTY(mProcess) != 0)
|
||||
{
|
||||
duk_push_int(ctx, ILibProcessPipe_Process_GetPTY(mProcess));
|
||||
ILibDuktape_CreateReadonlyProperty(ctx, "pty");
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "tcsetsize", ILibDuktape_ChildProcess_tcsetsize, 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (callback != NULL) { ILibDuktape_EventEmitter_AddOnce(emitter, "exit", callback); }
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ typedef struct ILibProcessPipe_Process_Object
|
||||
DWORD PID;
|
||||
#else
|
||||
pid_t PID;
|
||||
int PTY;
|
||||
#endif
|
||||
void *userObject;
|
||||
|
||||
@@ -908,9 +909,11 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
w.ws_xpixel = 0;
|
||||
w.ws_ypixel = 0;
|
||||
pid = forkpty(&pipe, NULL, NULL, &w);
|
||||
retVal->PTY = pipe;
|
||||
retVal->stdIn = ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(pipeManager, pipe, extraMemorySize);
|
||||
retVal->stdIn->mProcess = retVal;
|
||||
retVal->stdOut = ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(pipeManager, pipe, extraMemorySize);
|
||||
|
||||
retVal->stdIn->mProcess = retVal;
|
||||
ILibProcessPipe_Pipe_SetBrokenPipeHandler(retVal->stdOut, ILibProcessPipe_Process_BrokenPipeSink);
|
||||
retVal->stdOut->mProcess = retVal;
|
||||
#else
|
||||
@@ -1850,5 +1853,6 @@ int ILibProcessPipe_Pipe_WriteEx(ILibProcessPipe_Pipe targetPipe, char *buffer,
|
||||
DWORD ILibProcessPipe_Process_GetPID(ILibProcessPipe_Process p) { return(p != NULL ? (DWORD)((ILibProcessPipe_Process_Object*)p)->PID : 0); }
|
||||
#else
|
||||
pid_t ILibProcessPipe_Process_GetPID(ILibProcessPipe_Process p) { return(p != NULL ? (pid_t)((ILibProcessPipe_Process_Object*)p)->PID : 0); }
|
||||
int ILibProcessPipe_Process_GetPTY(ILibProcessPipe_Process p) { return(p != NULL ? ((ILibProcessPipe_Process_Object*)p)->PTY : 0); }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ ILibProcessPipe_Pipe ILibProcessPipe_Process_GetStdOut(ILibProcessPipe_Process p
|
||||
DWORD ILibProcessPipe_Process_GetPID(ILibProcessPipe_Process p);
|
||||
#else
|
||||
pid_t ILibProcessPipe_Process_GetPID(ILibProcessPipe_Process p);
|
||||
int ILibProcessPipe_Process_GetPTY(ILibProcessPipe_Process p);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user