aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-08-22 10:58:02 +0200
committerGitHub Enterprise <[email protected]>2024-08-22 10:58:02 +0200
commit57b56f20894a982bbc37e7784f7d0159bece5d5b (patch)
tree4585303413b42f159c99ffde932d8f2fb058fdee /src
parentif a zenserver is already using our named mutex - exit with error code instea... (diff)
downloadzen-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')
-rw-r--r--src/zenserver/main.cpp25
-rw-r--r--src/zenutil/zenserverprocess.cpp54
2 files changed, 63 insertions, 16 deletions
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp
index 93516f5fd..25a5d5cf5 100644
--- a/src/zenserver/main.cpp
+++ b/src/zenserver/main.cpp
@@ -109,12 +109,27 @@ ZenEntryPoint::Run()
{
if (m_ServerOptions.OwnerPid)
{
- if (!IsProcessRunning(m_ServerOptions.OwnerPid))
+ std::error_code Ec;
+ if (!IsProcessRunning(m_ServerOptions.OwnerPid, Ec))
{
- ZEN_WARN("Sponsor owner pid {} is no longer running, will not add sponsor to process listening to port {} (pid: {})",
- m_ServerOptions.OwnerPid,
- m_ServerOptions.BasePort,
- Entry->Pid.load());
+ if (Ec)
+ {
+ ZEN_WARN(
+ "Sponsor owner pid {} can not be checked for running state, reason: '{}'. Will not add sponsor to process "
+ "listening to port {} (pid: {})",
+ m_ServerOptions.OwnerPid,
+ Ec.message(),
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
+ }
+ else
+ {
+ ZEN_WARN(
+ "Sponsor owner pid {} is no longer running, will not add sponsor to process listening to port {} (pid: {})",
+ m_ServerOptions.OwnerPid,
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
+ }
std::exit(1);
}
ZEN_INFO(
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)