diff options
author | tcmal <me@aria.rip> | 2024-06-21 22:27:01 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-06-26 20:57:28 +0100 |
commit | c4cf4336c823a1d5681523e6ef5cdfaa270f71ac (patch) | |
tree | 74c835f340b754d6bcfa2b372215a9a1d8b212eb /src | |
parent | 7639ceef0108660453f15ebacc3dd074377b5079 (diff) |
implement cleanup_process_children
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 25 |
1 files changed, 22 insertions, 3 deletions
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)) {} + }; } |