aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/zenserverprocess.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-03-21 13:03:41 +0100
committerGitHub Enterprise <[email protected]>2024-03-21 13:03:41 +0100
commitf60aec8607aa4ef70b4653d201c854b00a538951 (patch)
treea10a9b168fbc4f1f9a64c52f3126faecf845b795 /src/zenutil/zenserverprocess.cpp
parent5.4.2-pre6 (diff)
downloadzen-f60aec8607aa4ef70b4653d201c854b00a538951.tar.xz
zen-f60aec8607aa4ef70b4653d201c854b00a538951.zip
harden attach sponsor process (#14)
- Improvement: Delay exiting due to no sponsor processes by one second to handle race conditions - Improvement: Safer IsProcessRunning check - Improvement: make sure we can RequestApplicationExit safely from any thread
Diffstat (limited to 'src/zenutil/zenserverprocess.cpp')
-rw-r--r--src/zenutil/zenserverprocess.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/zenutil/zenserverprocess.cpp b/src/zenutil/zenserverprocess.cpp
index 3667ad2c6..7725d0af6 100644
--- a/src/zenutil/zenserverprocess.cpp
+++ b/src/zenutil/zenserverprocess.cpp
@@ -308,7 +308,7 @@ ZenServerState::Sweep()
if (Entry.DesiredListenPort)
{
- if (IsProcessRunning(Entry.Pid) == false)
+ if (Entry.Pid != 0 && IsProcessRunning(Entry.Pid) == false)
{
ZEN_DEBUG("Sweep - pid {} not running, reclaiming entry (port {})", Entry.Pid.load(), Entry.DesiredListenPort.load());
@@ -363,18 +363,15 @@ ZenServerState::ZenServerEntry::AddSponsorProcess(uint32_t PidToAdd)
{
for (std::atomic<uint32_t>& PidEntry : SponsorPids)
{
- if (PidEntry.load(std::memory_order_relaxed) == 0)
+ if (PidEntry.load(std::memory_order_relaxed) == PidToAdd)
{
- uint32_t Expected = 0;
- if (PidEntry.compare_exchange_strong(Expected, PidToAdd))
- {
- // Success!
- return true;
- }
+ // Success, the because pid is already in the list
+ return true;
}
- else if (PidEntry.load(std::memory_order_relaxed) == PidToAdd)
+ uint32_t Expected = 0;
+ if (PidEntry.compare_exchange_strong(Expected, PidToAdd))
{
- // Success, the because pid is already in the list
+ // Success!
return true;
}
}