diff --git a/microscript/ILibDuktape_ChildProcess.c b/microscript/ILibDuktape_ChildProcess.c index 173e2fa..54a6795 100644 --- a/microscript/ILibDuktape_ChildProcess.c +++ b/microscript/ILibDuktape_ChildProcess.c @@ -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) diff --git a/microstack/ILibProcessPipe.c b/microstack/ILibProcessPipe.c index 2a20069..d9cdccb 100644 --- a/microstack/ILibProcessPipe.c +++ b/microstack/ILibProcessPipe.c @@ -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; diff --git a/microstack/ILibProcessPipe.h b/microstack/ILibProcessPipe.h index 2d35c45..fd23d6a 100644 --- a/microstack/ILibProcessPipe.h +++ b/microstack/ILibProcessPipe.h @@ -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);