From 5a2fd23a721e57bb5eee9c7b01a8a2d24ca18d1c Mon Sep 17 00:00:00 2001 From: David Martos Date: Sun, 12 Jan 2025 21:58:15 +0100 Subject: [PATCH] fix Steam stop function, it can get into an infinite loop (#431) * fix Steam stop function, it can get into an infinite loop * add log * skip process stop if not able to send the quit/kill signals Ont the Steam Deck, it will try to kill the steamos-manager process, which is owned by root. --- src/steam/restarter.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/steam/restarter.rs b/src/steam/restarter.rs index d409bc6..2732f87 100644 --- a/src/steam/restarter.rs +++ b/src/steam/restarter.rs @@ -14,18 +14,32 @@ pub fn ensure_steam_stopped() { let processes = s.processes_by_name(os_steam_name); for process in processes { let mut s = System::new(); - process.kill_with(sysinfo::Signal::Quit); - process.kill_with(sysinfo::Signal::Kill); + + let quit_res = process.kill_with(sysinfo::Signal::Quit); + let kill_res = process.kill_with(sysinfo::Signal::Kill); + + if quit_res == Some(false) && kill_res == Some(false) { + // Couldn't kill the process, this could be because it was already killed or we don't have permissions + // For instance, the process "steamos-manager" in the Steam Deck is owned by root + continue; + } + let pid = process.pid(); + let process_name = process.name(); let pid_arr = [pid]; let process_to_update = ProcessesToUpdate::Some(&pid_arr); - while s.refresh_processes_specifics(process_to_update, true,ProcessRefreshKind::everything()) == 0{ - println!("Waiting for steam to stop"); + + while s.refresh_processes_specifics(process_to_update, true,ProcessRefreshKind::everything()) > 0 + // The process is still alive + && s.process(pid).is_some() + { + println!("Waiting for steam to stop. PID: {pid:?} Name: {process_name:?}"); sleep(Duration::from_millis(500)); process.kill_with(sysinfo::Signal::Quit); process.kill_with(sysinfo::Signal::Kill); } } + println!("Steam is stopped"); } #[cfg(target_os = "windows")] pub fn ensure_steam_started(settings: &super::SteamSettings) {