Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix game processes being in a zombie state when exiting #33

Merged
merged 4 commits into from
Aug 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,32 @@ unsafe extern "C" fn start_game_clicked(

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

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

#[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

let mut child = match _child {
Ok(child) => child,
Err(e) => {
warn!("Failure starting the game process {e}");
return false;
}
};

std::thread::spawn(move || match child.wait() {
Ok(exit_status) => {
info!("Game process exited with {}", exit_status);
}
Err(e) => {
warn!("Failure waiting for the game process' exit: {e}");
}
});
}

return false;
}

Expand Down