Skip to content

Commit

Permalink
Wait for the game process to exit on Unix systems
Browse files Browse the repository at this point in the history
This patch fixes the issue where the spawned game processes would never be removed from the system process list on Unix systems.
The processes would stay in a zombie state because we weren't waiting for their exit as we should be doing under Unix systems.
  • Loading branch information
Refragg committed Aug 19, 2023
1 parent bbae813 commit eeb77e2
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use std::{
},
};

#[cfg(all(unix, feature = "auto-splitting"))]
use std::thread;

#[cfg(feature = "auto-splitting")]
mod auto_splitters;
mod ffi;
Expand Down Expand Up @@ -620,7 +623,29 @@ unsafe extern "C" fn start_game_clicked(

let mut process = Command::new(state.game_path.clone());

Check failure on line 624 in src/lib.rs

View workflow job for this annotation

GitHub Actions / format

Diff in /home/runner/work/obs-livesplit-one/obs-livesplit-one/src/lib.rs

process.spawn().ok();
let child = process.spawn().ok();

Check warning on line 626 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (Windows aarch64)

unused variable: `child`

Check warning on line 626 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (Windows i686)

unused variable: `child`

Check warning on line 626 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (Windows x86_64)

unused variable: `child`

Check warning on line 626 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (Windows x86_64-v3)

unused variable: `child`

#[cfg(unix)]
{
// For Unix systems only, spawn a new thread that waits for the process to exit.
// This avoids keeping the process in a zombie state and never letting go of it until
// the plugin is unloaded
thread::spawn(move || {

Check failure on line 633 in src/lib.rs

View workflow job for this annotation

GitHub Actions / format

Diff in /home/runner/work/obs-livesplit-one/obs-livesplit-one/src/lib.rs

Check failure on line 633 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (Linux arm Hardware Float)

failed to resolve: use of undeclared crate or module `thread`

Check failure on line 633 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (Linux armv7 Hardware Float)

failed to resolve: use of undeclared crate or module `thread`

Check failure on line 633 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (Linux i686)

failed to resolve: use of undeclared crate or module `thread`
if child.is_none() {
warn!("Failure starting the game process");
return;
};

let exit_status = child.unwrap().wait();
if let Err(e) = exit_status {
warn!("Failure waiting for the game process' exit: {e}");
return;

Check failure on line 642 in src/lib.rs

View workflow job for this annotation

GitHub Actions / format

Diff in /home/runner/work/obs-livesplit-one/obs-livesplit-one/src/lib.rs
};

info!("Game process exited with {}", exit_status.unwrap())
});
}

Check failure on line 648 in src/lib.rs

View workflow job for this annotation

GitHub Actions / format

Diff in /home/runner/work/obs-livesplit-one/obs-livesplit-one/src/lib.rs
return false;
}

Expand Down

0 comments on commit eeb77e2

Please sign in to comment.