Lines Matching refs:process
138 deProcess* process = (deProcess*)deCalloc(sizeof(deProcess)); in deProcess_create() local
139 if (!process) in deProcess_create()
142 process->state = PROCESSSTATE_NOT_STARTED; in deProcess_create()
144 return process; in deProcess_create()
147 static void deProcess_cleanupHandles (deProcess* process) in deProcess_cleanupHandles() argument
149 if (process->standardIn) in deProcess_cleanupHandles()
150 deFile_destroy(process->standardIn); in deProcess_cleanupHandles()
152 if (process->standardOut) in deProcess_cleanupHandles()
153 deFile_destroy(process->standardOut); in deProcess_cleanupHandles()
155 if (process->standardErr) in deProcess_cleanupHandles()
156 deFile_destroy(process->standardErr); in deProcess_cleanupHandles()
158 process->pid = 0; in deProcess_cleanupHandles()
159 process->standardIn = DE_NULL; in deProcess_cleanupHandles()
160 process->standardOut = DE_NULL; in deProcess_cleanupHandles()
161 process->standardErr = DE_NULL; in deProcess_cleanupHandles()
164 void deProcess_destroy (deProcess* process) in deProcess_destroy() argument
167 if (deProcess_isRunning(process)) in deProcess_destroy()
169 deProcess_kill(process); in deProcess_destroy()
170 deProcess_waitForFinish(process); in deProcess_destroy()
173 deProcess_cleanupHandles(process); in deProcess_destroy()
174 deFree(process->lastError); in deProcess_destroy()
175 deFree(process); in deProcess_destroy()
178 const char* deProcess_getLastError (const deProcess* process) in deProcess_getLastError() argument
180 return process->lastError ? process->lastError : "No error"; in deProcess_getLastError()
183 int deProcess_getExitCode (const deProcess* process) in deProcess_getExitCode() argument
185 return process->exitCode; in deProcess_getExitCode()
188 static deBool deProcess_setError (deProcess* process, const char* error) in deProcess_setError() argument
190 if (process->lastError) in deProcess_setError()
192 deFree(process->lastError); in deProcess_setError()
193 process->lastError = DE_NULL; in deProcess_setError()
196 process->lastError = deStrdup(error); in deProcess_setError()
197 return process->lastError != DE_NULL; in deProcess_setError()
200 static deBool deProcess_setErrorFromErrno (deProcess* process, const char* message) in deProcess_setErrorFromErrno() argument
205 return deProcess_setError(process, message); in deProcess_setErrorFromErrno()
216 deBool deProcess_start (deProcess* process, const char* commandLine, const char* workingDirectory) in deProcess_start() argument
224 if (process->state == PROCESSSTATE_RUNNING) in deProcess_start()
226 deProcess_setError(process, "Process already running"); in deProcess_start()
229 else if (process->state == PROCESSSTATE_FINISHED) in deProcess_start()
231 deProcess_cleanupHandles(process); in deProcess_start()
232 process->state = PROCESSSTATE_NOT_STARTED; in deProcess_start()
237 deProcess_setErrorFromErrno(process, "pipe() failed"); in deProcess_start()
251 deProcess_setErrorFromErrno(process, "fork() failed"); in deProcess_start()
336 deProcess_setError(process, errBuf); in deProcess_start()
346 process->pid = pid; in deProcess_start()
347 process->state = PROCESSSTATE_RUNNING; in deProcess_start()
354 process->standardIn = deFile_createFromHandle((deUintptr)pipeIn[1]); in deProcess_start()
355 process->standardOut = deFile_createFromHandle((deUintptr)pipeOut[0]); in deProcess_start()
356 process->standardErr = deFile_createFromHandle((deUintptr)pipeErr[0]); in deProcess_start()
358 if (!process->standardIn) in deProcess_start()
361 if (!process->standardOut) in deProcess_start()
364 if (!process->standardErr) in deProcess_start()
371 deBool deProcess_isRunning (deProcess* process) in deProcess_isRunning() argument
373 if (process->state == PROCESSSTATE_RUNNING) in deProcess_isRunning()
377 if (waitpid(process->pid, &status, WNOHANG) == 0) in deProcess_isRunning()
383 process->state = PROCESSSTATE_FINISHED; in deProcess_isRunning()
393 deBool deProcess_waitForFinish (deProcess* process) in deProcess_waitForFinish() argument
398 if (process->state != PROCESSSTATE_RUNNING) in deProcess_waitForFinish()
400 deProcess_setError(process, "Process is not running"); in deProcess_waitForFinish()
405 while ((waitResult = waitpid(process->pid, &status, 0)) != process->pid) in deProcess_waitForFinish()
408 if (waitResult != process->pid) in deProcess_waitForFinish()
410 deProcess_setErrorFromErrno(process, "waitpid() failed"); in deProcess_waitForFinish()
416 deProcess_setErrorFromErrno(process, "waitpid() failed"); in deProcess_waitForFinish()
420 process->exitCode = WEXITSTATUS(status); in deProcess_waitForFinish()
421 process->state = PROCESSSTATE_FINISHED; in deProcess_waitForFinish()
425 static deBool deProcess_sendSignal (deProcess* process, int sigNum) in deProcess_sendSignal() argument
427 if (process->state != PROCESSSTATE_RUNNING) in deProcess_sendSignal()
429 deProcess_setError(process, "Process is not running"); in deProcess_sendSignal()
433 if (kill(process->pid, sigNum) == 0) in deProcess_sendSignal()
437 deProcess_setErrorFromErrno(process, "kill() failed"); in deProcess_sendSignal()
442 deBool deProcess_terminate (deProcess* process) in deProcess_terminate() argument
444 return deProcess_sendSignal(process, SIGTERM); in deProcess_terminate()
447 deBool deProcess_kill (deProcess* process) in deProcess_kill() argument
449 return deProcess_sendSignal(process, SIGKILL); in deProcess_kill()
452 deFile* deProcess_getStdIn (deProcess* process) in deProcess_getStdIn() argument
454 return process->standardIn; in deProcess_getStdIn()
457 deFile* deProcess_getStdOut (deProcess* process) in deProcess_getStdOut() argument
459 return process->standardOut; in deProcess_getStdOut()
462 deFile* deProcess_getStdErr (deProcess* process) in deProcess_getStdErr() argument
464 return process->standardErr; in deProcess_getStdErr()
467 deBool deProcess_closeStdIn (deProcess* process) in deProcess_closeStdIn() argument
469 if (process->standardIn) in deProcess_closeStdIn()
471 deFile_destroy(process->standardIn); in deProcess_closeStdIn()
472 process->standardIn = DE_NULL; in deProcess_closeStdIn()
479 deBool deProcess_closeStdOut (deProcess* process) in deProcess_closeStdOut() argument
481 if (process->standardOut) in deProcess_closeStdOut()
483 deFile_destroy(process->standardOut); in deProcess_closeStdOut()
484 process->standardOut = DE_NULL; in deProcess_closeStdOut()
491 deBool deProcess_closeStdErr (deProcess* process) in deProcess_closeStdErr() argument
493 if (process->standardErr) in deProcess_closeStdErr()
495 deFile_destroy(process->standardErr); in deProcess_closeStdErr()
496 process->standardErr = DE_NULL; in deProcess_closeStdErr()
531 static deBool deProcess_setError (deProcess* process, const char* error) in deProcess_setError() argument
533 if (process->lastError) in deProcess_setError()
535 deFree(process->lastError); in deProcess_setError()
536 process->lastError = DE_NULL; in deProcess_setError()
539 process->lastError = deStrdup(error); in deProcess_setError()
540 return process->lastError != DE_NULL; in deProcess_setError()
543 static deBool deProcess_setErrorFromWin32 (deProcess* process, const char* msg) in deProcess_setErrorFromWin32() argument
558 return deProcess_setError(process, errBuf); in deProcess_setErrorFromWin32()
564 return deProcess_setError(process, errBuf); in deProcess_setErrorFromWin32()
570 deProcess* process = (deProcess*)deCalloc(sizeof(deProcess)); in deProcess_create() local
571 if (!process) in deProcess_create()
574 process->state = PROCESSSTATE_NOT_STARTED; in deProcess_create()
576 return process; in deProcess_create()
579 void deProcess_cleanupHandles (deProcess* process) in deProcess_cleanupHandles() argument
581 DE_ASSERT(!deProcess_isRunning(process)); in deProcess_cleanupHandles()
583 if (process->standardErr) in deProcess_cleanupHandles()
584 deFile_destroy(process->standardErr); in deProcess_cleanupHandles()
586 if (process->standardOut) in deProcess_cleanupHandles()
587 deFile_destroy(process->standardOut); in deProcess_cleanupHandles()
589 if (process->standardIn) in deProcess_cleanupHandles()
590 deFile_destroy(process->standardIn); in deProcess_cleanupHandles()
592 if (process->procInfo.hProcess) in deProcess_cleanupHandles()
593 CloseHandle(process->procInfo.hProcess); in deProcess_cleanupHandles()
595 if (process->procInfo.hThread) in deProcess_cleanupHandles()
596 CloseHandle(process->procInfo.hThread); in deProcess_cleanupHandles()
598 process->standardErr = DE_NULL; in deProcess_cleanupHandles()
599 process->standardOut = DE_NULL; in deProcess_cleanupHandles()
600 process->standardIn = DE_NULL; in deProcess_cleanupHandles()
601 process->procInfo.hProcess = DE_NULL; in deProcess_cleanupHandles()
602 process->procInfo.hThread = DE_NULL; in deProcess_cleanupHandles()
605 void deProcess_destroy (deProcess* process) in deProcess_destroy() argument
607 if (deProcess_isRunning(process)) in deProcess_destroy()
609 deProcess_kill(process); in deProcess_destroy()
610 deProcess_waitForFinish(process); in deProcess_destroy()
613 deProcess_cleanupHandles(process); in deProcess_destroy()
614 deFree(process->lastError); in deProcess_destroy()
615 deFree(process); in deProcess_destroy()
618 const char* deProcess_getLastError (const deProcess* process) in deProcess_getLastError() argument
620 return process->lastError ? process->lastError : "No error"; in deProcess_getLastError()
623 int deProcess_getExitCode (const deProcess* process) in deProcess_getExitCode() argument
625 return process->exitCode; in deProcess_getExitCode()
628 deBool deProcess_start (deProcess* process, const char* commandLine, const char* workingDirectory) in deProcess_start() argument
641 if (process->state == PROCESSSTATE_RUNNING) in deProcess_start()
643 deProcess_setError(process, "Process already running"); in deProcess_start()
646 else if (process->state == PROCESSSTATE_FINISHED) in deProcess_start()
649 deProcess_cleanupHandles(process); in deProcess_start()
650 process->state = PROCESSSTATE_NOT_STARTED; in deProcess_start()
665 deProcess_setErrorFromWin32(process, "CreatePipe() failed"); in deProcess_start()
674 deProcess_setErrorFromWin32(process, "CreatePipe() failed"); in deProcess_start()
685 deProcess_setErrorFromWin32(process, "CreatePipe() failed"); in deProcess_start()
702 …DE_NULL, TRUE /* inherit handles */, 0, DE_NULL, workingDirectory, &startInfo, &process->procInfo)) in deProcess_start()
705 deProcess_setErrorFromWin32(process, "CreateProcess() failed"); in deProcess_start()
718 process->state = PROCESSSTATE_RUNNING; in deProcess_start()
726 process->standardIn = deFile_createFromHandle((deUintptr)stdInWrite); in deProcess_start()
727 process->standardOut = deFile_createFromHandle((deUintptr)stdOutRead); in deProcess_start()
728 process->standardErr = deFile_createFromHandle((deUintptr)stdErrRead); in deProcess_start()
733 deBool deProcess_isRunning (deProcess* process) in deProcess_isRunning() argument
735 if (process->state == PROCESSSTATE_RUNNING) in deProcess_isRunning()
738 BOOL result = GetExitCodeProcess(process->procInfo.hProcess, (LPDWORD)&exitCode); in deProcess_isRunning()
742 deProcess_setErrorFromWin32(process, "GetExitCodeProcess() failed"); in deProcess_isRunning()
751 process->exitCode = exitCode; in deProcess_isRunning()
752 process->state = PROCESSSTATE_FINISHED; in deProcess_isRunning()
760 deBool deProcess_waitForFinish (deProcess* process) in deProcess_waitForFinish() argument
762 if (process->state == PROCESSSTATE_RUNNING) in deProcess_waitForFinish()
764 if (WaitForSingleObject(process->procInfo.hProcess, INFINITE) != WAIT_OBJECT_0) in deProcess_waitForFinish()
766 deProcess_setErrorFromWin32(process, "WaitForSingleObject() failed"); in deProcess_waitForFinish()
769 return !deProcess_isRunning(process); in deProcess_waitForFinish()
773 deProcess_setError(process, "Process is not running"); in deProcess_waitForFinish()
778 static deBool stopProcess (deProcess* process, deBool kill) in stopProcess() argument
780 if (process->state == PROCESSSTATE_RUNNING) in stopProcess()
782 if (!TerminateProcess(process->procInfo.hProcess, kill ? -1 : 0)) in stopProcess()
784 deProcess_setErrorFromWin32(process, "TerminateProcess() failed"); in stopProcess()
792 deProcess_setError(process, "Process is not running"); in stopProcess()
797 deBool deProcess_terminate (deProcess* process) in deProcess_terminate() argument
799 return stopProcess(process, DE_FALSE); in deProcess_terminate()
802 deBool deProcess_kill (deProcess* process) in deProcess_kill() argument
804 return stopProcess(process, DE_TRUE); in deProcess_kill()
807 deFile* deProcess_getStdIn (deProcess* process) in deProcess_getStdIn() argument
809 return process->standardIn; in deProcess_getStdIn()
812 deFile* deProcess_getStdOut (deProcess* process) in deProcess_getStdOut() argument
814 return process->standardOut; in deProcess_getStdOut()
817 deFile* deProcess_getStdErr (deProcess* process) in deProcess_getStdErr() argument
819 return process->standardErr; in deProcess_getStdErr()
822 deBool deProcess_closeStdIn (deProcess* process) in deProcess_closeStdIn() argument
824 if (process->standardIn) in deProcess_closeStdIn()
826 deFile_destroy(process->standardIn); in deProcess_closeStdIn()
827 process->standardIn = DE_NULL; in deProcess_closeStdIn()
834 deBool deProcess_closeStdOut (deProcess* process) in deProcess_closeStdOut() argument
836 if (process->standardOut) in deProcess_closeStdOut()
838 deFile_destroy(process->standardOut); in deProcess_closeStdOut()
839 process->standardOut = DE_NULL; in deProcess_closeStdOut()
846 deBool deProcess_closeStdErr (deProcess* process) in deProcess_closeStdErr() argument
848 if (process->standardErr) in deProcess_closeStdErr()
850 deFile_destroy(process->standardErr); in deProcess_closeStdErr()
851 process->standardErr = DE_NULL; in deProcess_closeStdErr()