int CleanUp(int exitCode) { DWORD processExitCode; BOOL error = FALSE; // Signal termination to the pipe redirection threads SignalHandlingRedirecionPipesForExiting(); // Close all existing pipes // Some programs can get confused if we disconnect before closing CloseHandleSafe(gIpcPipe); CloseHandleSafe(gStdInPipe); CloseHandleSafe(gStdOutPipe); CloseHandleSafe(gStdErrPipe); // Wait the termination of all pipe redirection threads and check the termination cause error = WaitHandlingRedirecionPipesForExiting(); // Pass-through the stub process termination error if (gStubProcess != NULL && WaitForSingleObject(gStubProcess, MAX_WAITING_TIME) != WAIT_FAILED && GetExitCodeProcess(gStubProcess, &processExitCode) && processExitCode != ERROR_SUCCESS) { SetLastError(processExitCode); SysError(); error = TRUE; } // if this program or the stub had errors and the target process returned // a success exit code, then exit with failure if (error && exitCode == EXIT_SUCCESS) exitCode = EXIT_FAILURE; // Close the handles to pipe redirection threads and to the target process CloseHandleSafe(gStdInThread); CloseHandleSafe(gStdOutThread); CloseHandleSafe(gStdErrThread); CloseHandleSafe(gStubProcess); CloseHandleSafe(gTargetProcess); // Free allocated memory for strings StringFree(gCurrentDirectory); StringFree(gCmdLine); return exitCode; }
bool runner::wait_for(const unsigned long &interval) { if (get_process_status() == process_spawner_crash || get_process_status() & process_finished_normal) { return true; } if (!running_async) { return false; } wait_for_init(interval); if (WaitForSingleObject(process_info.hProcess, interval) != WAIT_OBJECT_0) { return false; } WaitForSingleObject(running_thread, interval); CloseHandleSafe(running_thread); return true; }
handle_buffer_c::~handle_buffer_c() { if (!dont_close_handle_) { CloseHandleSafe(stream); } }
runner::~runner() { CloseHandleSafe(process_info.hProcess); CloseHandleSafe(process_info.hThread); }
void runner::free() { CloseHandleSafe(process_info.hProcess); CloseHandleSafe(process_info.hThread); }