1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00

Added ability to end stdin on child_process spawned process

This commit is contained in:
Bryan Roe
2019-09-06 21:41:48 -07:00
parent dabeb6e2ba
commit 72db242dee
3 changed files with 38 additions and 1 deletions

View File

@@ -88,6 +88,11 @@ ILibTransport_DoneState ILibDuktape_ChildProcess_SubProcess_StdIn_WriteHandler(I
}
void ILibDuktape_ChildProcess_SubProcess_StdIn_EndHandler(ILibDuktape_WritableStream *sender, void *user)
{
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
if (ILibMemory_CanaryOK(p->childProcess))
{
ILibProcessPipe_Process_CloseStdIn(p->childProcess);
}
}
void ILibDuktape_ChildProcess_SubProcess_ExitHandler(ILibProcessPipe_Process sender, int exitCode, void* user)

View File

@@ -972,6 +972,14 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
close(retVal->stdIn->mPipe_ReadEnd);
close(retVal->stdOut->mPipe_WriteEnd);
int f = fcntl(STDIN_FILENO, F_GETFL);
f &= ~O_NONBLOCK;
fcntl(STDIN_FILENO, F_SETFL, f);
f = fcntl(STDOUT_FILENO, F_GETFL);
f &= ~O_NONBLOCK;
fcntl(STDOUT_FILENO, F_SETFL, f);
}
}
if (UID != -1 && UID != 0)
@@ -1621,6 +1629,20 @@ void ILibProcessPipe_Process_AddHandlers(ILibProcessPipe_Process module, int buf
#endif
}
}
void ILibProcessPipe_Pipe_Close(ILibProcessPipe_Pipe po)
{
ILibProcessPipe_PipeObject* pipeObject = (ILibProcessPipe_PipeObject*)po;
if (pipeObject != NULL)
{
#ifdef WIN32
CloseHandle(pipeObject->mPipe_WriteEnd);
pipeObject->mPipe_WriteEnd = NULL;
#else
close(pipeObject->mPipe_WriteEnd);
pipeObject->mPipe_WriteEnd = -1;
#endif
}
}
ILibTransport_DoneState ILibProcessPipe_Pipe_Write(ILibProcessPipe_Pipe po, char* buffer, int bufferLen, ILibTransport_MemoryOwnership ownership)
{
@@ -1697,7 +1719,14 @@ ILibTransport_DoneState ILibProcessPipe_Pipe_Write(ILibProcessPipe_Pipe po, char
return retVal;
}
void ILibProcessPipe_Process_CloseStdIn(ILibProcessPipe_Process p)
{
ILibProcessPipe_Process_Object *j = (ILibProcessPipe_Process_Object*)p;
if (ILibMemory_CanaryOK(j))
{
ILibProcessPipe_Pipe_Close(j->stdIn);
}
}
ILibTransport_DoneState ILibProcessPipe_Process_WriteStdIn(ILibProcessPipe_Process p, char* buffer, int bufferLen, ILibTransport_MemoryOwnership ownership)
{
ILibProcessPipe_Process_Object *j = (ILibProcessPipe_Process_Object*)p;

View File

@@ -82,6 +82,9 @@ void ILibProcessPipe_Process_SoftKill(ILibProcessPipe_Process p);
void ILibProcessPipe_Process_AddHandlers(ILibProcessPipe_Process module, int bufferSize, ILibProcessPipe_Process_ExitHandler exitHandler, ILibProcessPipe_Process_OutputHandler stdOut, ILibProcessPipe_Process_OutputHandler stdErr, ILibProcessPipe_Process_SendOKHandler sendOk, void *user);
void ILibProcessPipe_Process_UpdateUserObject(ILibProcessPipe_Process module, void *userObj);
ILibTransport_DoneState ILibProcessPipe_Process_WriteStdIn(ILibProcessPipe_Process p, char* buffer, int bufferLen, ILibTransport_MemoryOwnership ownership);
void ILibProcessPipe_Process_CloseStdIn(ILibProcessPipe_Process p);
void ILibProcessPipe_Pipe_Close(ILibProcessPipe_Pipe po);
void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject);
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject);
void ILibProcessPipe_Pipe_SwapBuffers(ILibProcessPipe_Pipe pipeObject, char* newBuffer, int newBufferLen, int newBufferReadOffset, int newBufferTotalBytesRead, char **oldBuffer, int *oldBufferLen, int *oldBufferReadOffset, int *oldBufferTotalBytesRead);