From c4cf4336c823a1d5681523e6ef5cdfaa270f71ac Mon Sep 17 00:00:00 2001 From: tcmal Date: Fri, 21 Jun 2024 22:27:01 +0100 Subject: implement cleanup_process_children --- src/main.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 09ef1f2..a5091ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,13 @@ use clients::ClientState; use conn_info::Connection; pub use error::*; +use nix::{ + sys::{ + signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal}, + wait::{waitpid, WaitPidFlag}, + }, + unistd::Pid, +}; use xcb::{ x::{self, PropertyNotifyEvent}, Connection as RawConnection, Event, Extension, @@ -117,7 +124,19 @@ impl<'a> WM<'a> { /// Cleanup this process' children and set some flags. /// This is necessary when used with `startx`. fn cleanup_process_children() { - // TODO: dont transform children into zombies when they terminate - // TODO: cleanup zombies - // todo!() + unsafe { + // Don't transform children into zombies when they terminate + sigaction( + Signal::SIGCHLD, + &SigAction::new( + SigHandler::SigIgn, + SaFlags::SA_NOCLDSTOP | SaFlags::SA_NOCLDWAIT | SaFlags::SA_RESTART, + SigSet::empty(), + ), + ) + .unwrap(); + + // Immediately wait for zombie processes to die - sometimes these come from startx. + while let Ok(_) = waitpid(Pid::from_raw(-1), Some(WaitPidFlag::WNOHANG)) {} + }; } -- cgit v1.2.3