From 57b56f20894a982bbc37e7784f7d0159bece5d5b Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 22 Aug 2024 10:58:02 +0200 Subject: safer calls to IsProcessRunning (#131) * safer calls to IsProcessRunning to handle cases where we can't check status of processes --- src/zenserver/main.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/zenserver/main.cpp') 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( -- cgit v1.2.3