[pbs-devel] [PATCH proxmox] daemon: clean up middle process of double fork

Dominik Csapak d.csapak at proxmox.com
Fri Nov 29 16:37:44 CET 2024


so we don't leave around a zombie process when the old daemon still
needs to run, because of e.g. a running task.

Since this is mostly a cosmetic issue though, only try a clean up
once, so we don't unnecessarily block or run into other issues here.
(It could happen that it didn't exit at that point, but it's very
unlikely.)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
maybe the comment could be improved, but i tried to be not overly
verbose there, since it's not really an issue anyway

 proxmox-daemon/src/server.rs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/proxmox-daemon/src/server.rs b/proxmox-daemon/src/server.rs
index efea9078..edc64795 100644
--- a/proxmox-daemon/src/server.rs
+++ b/proxmox-daemon/src/server.rs
@@ -165,10 +165,12 @@ impl Reloader {
                 // No matter how we managed to get here, this is the time where we bail out quickly:
                 unsafe { libc::_exit(-1) }
             }
-            Ok(ForkResult::Parent { child }) => {
+            Ok(ForkResult::Parent {
+                child: middle_child,
+            }) => {
                 log::debug!(
                     "forked off a new server (first pid: {}), waiting for 2nd pid",
-                    child
+                    middle_child
                 );
                 std::mem::drop(pnew);
                 let mut pold = std::fs::File::from(pold);
@@ -211,6 +213,13 @@ impl Reloader {
                     log::error!("child vanished during reload: {}", e);
                 }
 
+                // try exactly once to get rid of the zombie process of middle_child, but
+                // non blocking and without error handling, since it's just cosmetic
+                let _ = nix::sys::wait::waitpid(
+                    middle_child,
+                    Some(nix::sys::wait::WaitPidFlag::WNOHANG),
+                );
+
                 Ok(())
             }
             Err(e) => {
-- 
2.39.5





More information about the pbs-devel mailing list