diff options
| author | Dan Engelbrecht <[email protected]> | 2024-03-21 13:03:41 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-03-21 13:03:41 +0100 |
| commit | f60aec8607aa4ef70b4653d201c854b00a538951 (patch) | |
| tree | a10a9b168fbc4f1f9a64c52f3126faecf845b795 /src/zenutil/zenserverprocess.cpp | |
| parent | 5.4.2-pre6 (diff) | |
| download | zen-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.cpp | 17 |
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; } } |