From 9d0e1e88cea6bf9cbb59dd508d91e19014635ffa Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 24 May 2023 16:12:44 +0200 Subject: [PATCH] fix(input): zombie process from Action::Spawn Each invocation of `Action::Spawn` was spawning a process without waiting on the child; resulting in an accumulation of zombie sh processes. This will create background threads which waits on the child to ensure that they are reaped on exit. --- src/input/mod.rs | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 733fb479..4208fafc 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1137,24 +1137,33 @@ impl State { workspace.toggle_floating_window(seat); } Action::Spawn(command) => { - if let Err(err) = std::process::Command::new("/bin/sh") - .arg("-c") - .arg(command.clone()) - .env("WAYLAND_DISPLAY", &self.common.socket) - .env( - "DISPLAY", - &self - .common - .xwayland_state - .as_ref() - .map(|s| format!(":{}", s.display)) - .unwrap_or(String::new()), - ) - .env_remove("COSMIC_SESSION_SOCK") - .spawn() - { - warn!(?err, "Failed to spawn \"{}\"", command); - } + let wayland_display = self.common.socket.clone(); + + let display = self + .common + .xwayland_state + .as_ref() + .map(|s| format!(":{}", s.display)) + .unwrap_or_default(); + + std::thread::spawn(move || { + let mut cmd = std::process::Command::new("/bin/sh"); + + cmd.arg("-c") + .arg(command.clone()) + .env("WAYLAND_DISPLAY", &wayland_display) + .env("DISPLAY", &display) + .env_remove("COSMIC_SESSION_SOCK"); + + match cmd.spawn() { + Ok(mut child) => { + let _res = child.wait(); + } + Err(err) => { + tracing::warn!(?err, "Failed to spawn \"{}\"", command); + } + } + }); } } }