diff options
| author | Dan Engelbrecht <[email protected]> | 2024-08-22 10:58:02 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-08-22 10:58:02 +0200 |
| commit | 57b56f20894a982bbc37e7784f7d0159bece5d5b (patch) | |
| tree | 4585303413b42f159c99ffde932d8f2fb058fdee /src/zenutil/zenserverprocess.cpp | |
| parent | if a zenserver is already using our named mutex - exit with error code instea... (diff) | |
| download | zen-57b56f20894a982bbc37e7784f7d0159bece5d5b.tar.xz zen-57b56f20894a982bbc37e7784f7d0159bece5d5b.zip | |
safer calls to IsProcessRunning (#131)
* safer calls to IsProcessRunning to handle cases where we can't check status of processes
Diffstat (limited to 'src/zenutil/zenserverprocess.cpp')
| -rw-r--r-- | src/zenutil/zenserverprocess.cpp | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/src/zenutil/zenserverprocess.cpp b/src/zenutil/zenserverprocess.cpp index 84544bac8..29d590d00 100644 --- a/src/zenutil/zenserverprocess.cpp +++ b/src/zenutil/zenserverprocess.cpp @@ -249,7 +249,8 @@ ZenServerState::Lookup(int DesiredListenPort) const { if (DesiredListenPort == 0 || (EntryPort == DesiredListenPort)) { - if (IsProcessRunning(m_Data[i].Pid)) + std::error_code _; + if (IsProcessRunning(m_Data[i].Pid, _)) { return &m_Data[i]; } @@ -270,7 +271,8 @@ ZenServerState::LookupByEffectivePort(int Port) const { if (EntryPort == Port) { - if (IsProcessRunning(m_Data[i].Pid)) + std::error_code _; + if (IsProcessRunning(m_Data[i].Pid, _)) { return &m_Data[i]; } @@ -337,11 +339,21 @@ ZenServerState::Sweep() if (Entry.DesiredListenPort) { - if (Entry.Pid != 0 && IsProcessRunning(Entry.Pid) == false) + std::error_code ErrorCode; + if (Entry.Pid != 0 && IsProcessRunning(Entry.Pid, ErrorCode) == false) { - ZEN_DEBUG("Sweep - pid {} not running, reclaiming entry (port {})", Entry.Pid.load(), Entry.DesiredListenPort.load()); - - Entry.Reset(); + if (ErrorCode) + { + ZEN_WARN("Sweep - can not determine running state for pid {}, skipping entry (port {}). Reason: '{}'", + Entry.Pid.load(), + Entry.DesiredListenPort.load(), + ErrorCode.message()); + } + else + { + ZEN_DEBUG("Sweep - pid {} not running, reclaiming entry (port {})", Entry.Pid.load(), Entry.DesiredListenPort.load()); + Entry.Reset(); + } } } } @@ -361,9 +373,20 @@ ZenServerState::Snapshot(std::function<void(const ZenServerEntry&)>&& Callback) if (Entry.Pid != 0 && Entry.DesiredListenPort) { - if (IsProcessRunning(Entry.Pid.load())) + std::error_code ErrorCode; + if (IsProcessRunning(Entry.Pid.load(), ErrorCode)) { - Callback(Entry); + if (ErrorCode) + { + ZEN_WARN("Snapshot - can not determine running state for pid {}, skipping entry (port {}). Reason: '{}'", + Entry.Pid.load(), + Entry.DesiredListenPort.load(), + ErrorCode.message()); + } + else + { + Callback(Entry); + } } } } @@ -415,7 +438,8 @@ ZenServerState::ZenServerEntry::AddSponsorProcess(uint32_t PidToAdd, uint64_t Ti { return false; } - if (!IsProcessRunning(ServerPid)) + std::error_code _; + if (!IsProcessRunning(ServerPid, _)) { return false; } @@ -995,9 +1019,17 @@ ValidateLockFileInfo(const LockFileInfo& Info, std::string& OutReason) OutReason = fmt::format("process ({}) is invalid", Info.Pid); return false; } - if (!IsProcessRunning(Info.Pid)) + std::error_code ErrorCode; + if (!IsProcessRunning(Info.Pid, ErrorCode)) { - OutReason = fmt::format("process ({}) is not running", Info.Pid); + if (ErrorCode) + { + OutReason = fmt::format("process ({}) can not be checked. Reason: '{}'", Info.Pid, ErrorCode.message()); + } + else + { + OutReason = fmt::format("process ({}) is not running", Info.Pid); + } return false; } if (Info.SessionId == Oid::Zero) |