diff options
| author | Dan Engelbrecht <[email protected]> | 2023-11-15 14:41:55 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-15 14:41:55 +0100 |
| commit | 79347f5e118684f51e2b0c2a82f51e8667026062 (patch) | |
| tree | 6162a5fcfd97101e71e754e2a3a9a07326ffa537 /src/zencore/thread.cpp | |
| parent | Make object store endpoint S3 compatible. (#535) (diff) | |
| download | zen-79347f5e118684f51e2b0c2a82f51e8667026062.tar.xz zen-79347f5e118684f51e2b0c2a82f51e8667026062.zip | |
don't do blocking call to waitpid (#540)
fix process wait timeout
always use kill(pid, 0) to determine if process is running
Diffstat (limited to 'src/zencore/thread.cpp')
| -rw-r--r-- | src/zencore/thread.cpp | 38 |
1 files changed, 3 insertions, 35 deletions
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp index 99d7cdc61..758e88350 100644 --- a/src/zencore/thread.cpp +++ b/src/zencore/thread.cpp @@ -606,7 +606,7 @@ ProcessHandle::Terminate(int ExitCode) bSuccess = (WaitResult != WAIT_OBJECT_0); #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC ZEN_UNUSED(ExitCode); - bSuccess = (kill(m_Pid, SIGKILL) == 0); + bSuccess = (kill(m_Pid, SIGKILL) == 0); #endif if (!bSuccess) @@ -650,30 +650,6 @@ ProcessHandle::Wait(int TimeoutMs) break; } #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC - if (TimeoutMs < 0) - { - int WaitState = 0; - int Res = waitpid(m_Pid, &WaitState, WCONTINUED | WUNTRACED); - if (Res == -1) - { - int32_t LastError = zen::GetLastError(); - if (LastError == ECHILD || LastError == ESRCH) - { - return true; - } - ThrowSystemError(static_cast<uint32_t>(LastError), "Process::Wait waitpid failed"sv); - } - if (WIFEXITED(WaitState)) - { - return true; - } - if (WIFSIGNALED(WaitState)) - { - return true; - } - return false; - } - const int SleepMs = 20; timespec SleepTime = {0, SleepMs * 1000 * 1000}; for (int SleepedTimeMS = 0;; SleepedTimeMS += SleepMs) @@ -689,26 +665,18 @@ ProcessHandle::Wait(int TimeoutMs) } ThrowSystemError(static_cast<uint32_t>(LastError), "Process::Wait waitpid failed"sv); } - if (WIFEXITED(WaitState)) - { - return true; - } - if (WIFSIGNALED(WaitState)) - { - return true; - } if (kill(m_Pid, 0) < 0) { int32_t LastError = zen::GetLastError(); - if (LastError == ECHILD || LastError == ESRCH) + if (LastError == ESRCH) { return true; } ThrowSystemError(static_cast<uint32_t>(LastError), "Process::Wait kill failed"sv); } - if (SleepedTimeMS >= TimeoutMs) + if (TimeoutMs >= 0 && SleepedTimeMS >= TimeoutMs) { return false; } |