mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-20 11:35:48 +00:00
fix: don't crash when sending signals to child processes fails
This commit is contained in:
parent
3e21ca2eb8
commit
6d0d270254
2 changed files with 15 additions and 6 deletions
|
@ -252,6 +252,9 @@ impl App {
|
|||
}
|
||||
|
||||
pub fn shutdown_xrservice(&mut self) {
|
||||
if let Some(worker) = self.autostart_worker.as_ref() {
|
||||
worker.stop();
|
||||
}
|
||||
self.xrservice_ready = false;
|
||||
if let Some(w) = self.openxr_prober_worker.as_ref() {
|
||||
w.stop();
|
||||
|
@ -262,9 +265,6 @@ impl App {
|
|||
if let Some(worker) = self.xrservice_worker.as_ref() {
|
||||
worker.stop();
|
||||
}
|
||||
if let Some(worker) = self.autostart_worker.as_ref() {
|
||||
worker.stop();
|
||||
}
|
||||
self.libmonado = None;
|
||||
self.main_view
|
||||
.sender()
|
||||
|
|
|
@ -89,17 +89,26 @@ impl JobWorker {
|
|||
}
|
||||
|
||||
pub fn stop(&self) {
|
||||
if self.state.lock().unwrap().started && !self.state.lock().unwrap().exited {
|
||||
let should_stop_manually = {
|
||||
let state = self.state.lock().unwrap();
|
||||
state.started && !state.exited
|
||||
};
|
||||
if should_stop_manually {
|
||||
self.state.lock().unwrap().stop_requested = true;
|
||||
if let Some(pid) = self.state.lock().unwrap().current_pid {
|
||||
kill(pid, SIGTERM).expect("Could not send sigterm to process");
|
||||
if let Err(e) = kill(pid, SIGTERM) {
|
||||
eprintln!("Failed to send SIGTERM: {e:#?}");
|
||||
}
|
||||
let state = self.state.clone();
|
||||
thread::spawn(move || {
|
||||
sleep(Duration::from_secs(2));
|
||||
if let Ok(s) = state.lock() {
|
||||
if !s.exited {
|
||||
// process is still alive
|
||||
kill(pid, SIGKILL).expect("Failed to kill process");
|
||||
eprintln!("Process is still alive 2 seconds after SIGTERM, proceeding to send SIGKILL...");
|
||||
if let Err(e) = kill(pid, SIGKILL) {
|
||||
eprintln!("Failed to send SIGKILL: {e:#?}");
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue