From def3fc2aa840925d868674c78a4574d32093e0c7 Mon Sep 17 00:00:00 2001 From: Dillen Meijboom Date: Sun, 27 Mar 2022 11:36:10 +0200 Subject: [PATCH] Fix issue where shutdown was hanging on reaping child processes --- src/daemon.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index ade0b91..c9c3c69 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -1,16 +1,17 @@ use std::collections::HashMap; use std::path::PathBuf; -use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::Receiver; +use std::sync::Arc; use std::thread::sleep; use std::time::Duration; use anyhow::{anyhow, Result}; +use nix::sys::wait::WaitStatus::StillAlive; use nix::sys::wait::{waitpid, WaitPidFlag}; -use crate::{Event, log}; use crate::service::Service; +use crate::{log, Event}; fn check_service(service: &mut Service) -> Result<()> { if service.is_up() { @@ -134,8 +135,9 @@ impl Daemon { // Cleanup zombie processes before shutting down loop { - if !waitpid(None, Some(WaitPidFlag::WNOHANG)).is_ok() { - break; + match waitpid(None, Some(WaitPidFlag::WNOHANG)) { + Ok(StillAlive) | Err(_) => break, + Ok(_) => continue, } }