diff options
Diffstat (limited to 'src/zenserver/zenserver.cpp')
| -rw-r--r-- | src/zenserver/zenserver.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index daec743a0..d1faeb8b6 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -693,7 +693,6 @@ ZenServer::Run() if (m_IsPowerCycle) { ZEN_INFO("Power cycle mode enabled -- shutting down"); - RequestExit(0); } @@ -707,10 +706,12 @@ ZenServer::Run() void ZenServer::RequestExit(int ExitCode) { - RequestApplicationExit(ExitCode); - if (m_Http) + if (RequestApplicationExit(ExitCode)) { - m_Http->RequestExit(); + if (m_Http) + { + m_Http->RequestExit(); + } } } @@ -779,7 +780,7 @@ ZenServer::EnsureIoRunner() } void -ZenServer::EnqueueTimer() +ZenServer::EnqueueProcessMonitorTimer() { m_PidCheckTimer.expires_after(std::chrono::seconds(1)); m_PidCheckTimer.async_wait([this](const asio::error_code&) { CheckOwnerPid(); }); @@ -857,11 +858,10 @@ ZenServer::CheckSigInt() EnqueueSigIntTimer(); } -void -ZenServer::CheckOwnerPid() +bool +ZenServer::UpdateProcessMonitor() { // Pick up any new "owner" processes - std::set<uint32_t> AddedPids; for (auto& PidEntry : m_ServerEntry->SponsorPids) @@ -874,21 +874,38 @@ ZenServer::CheckOwnerPid() { m_ProcessMonitor.AddPid(ThisPid); - ZEN_INFO("added process with pid #{} as a sponsor process", ThisPid); + ZEN_INFO("added process with pid {} as a sponsor process", ThisPid); } } } } + return m_ProcessMonitor.IsRunning(); +} - if (m_ProcessMonitor.IsRunning()) +void +ZenServer::CheckOwnerPid() +{ + bool IsRunning = UpdateProcessMonitor(); + + if (IsRunning) { - EnqueueTimer(); + m_FoundNoActiveSponsors = false; + EnqueueProcessMonitorTimer(); } else { - ZEN_INFO(ZEN_APP_NAME " exiting since sponsor processes are all gone"); - - RequestExit(0); + // Delay exit one iteration to avoid race conditions where one process detaches + // and another attaches + if (m_FoundNoActiveSponsors) + { + ZEN_INFO(ZEN_APP_NAME " exiting since sponsor processes are all gone"); + RequestExit(0); + } + else + { + m_FoundNoActiveSponsors = true; + EnqueueProcessMonitorTimer(); + } } } |