fix: Make sure to exit after unwind

This commit is contained in:
Gerald Pinder 2024-10-11 19:40:55 -04:00
parent ceefc7175a
commit 1865a46c55

View file

@ -1,7 +1,7 @@
use std::{ use std::{
fs, fs,
path::PathBuf, path::PathBuf,
process::ExitCode, process,
sync::{atomic::AtomicBool, Arc, Mutex}, sync::{atomic::AtomicBool, Arc, Mutex},
thread, thread,
}; };
@ -92,10 +92,10 @@ where
let app = thread::spawn(app_exec); let app = thread::spawn(app_exec);
if matches!(app.join(), Ok(())) { if matches!(app.join(), Ok(())) {
exit_unwind(ExitCode::SUCCESS); exit_unwind(0);
} else { } else {
error!("App thread panic!"); error!("App thread panic!");
exit_unwind(ExitCode::FAILURE); exit_unwind(2);
} }
}); });
@ -132,7 +132,7 @@ where
}); });
drop(cid_list); drop(cid_list);
exit_unwind(ExitCode::FAILURE); exit_unwind(1);
} }
SIGTSTP => { SIGTSTP => {
if has_terminal { if has_terminal {
@ -154,8 +154,18 @@ where
} }
} }
fn exit_unwind(code: ExitCode) { struct ExitCode {
std::panic::resume_unwind(Box::new(code)); code: i32,
}
impl Drop for ExitCode {
fn drop(&mut self) {
process::exit(self.code);
}
}
fn exit_unwind(code: i32) {
std::panic::resume_unwind(Box::new(ExitCode { code }));
} }
fn send_signal_processes(sig: i32) { fn send_signal_processes(sig: i32) {