Skip to content

Commit

Permalink
fix: Make sure to exit after unwind
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpinder committed Oct 11, 2024
1 parent ceefc71 commit 1865a46
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions process/signal_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
fs,
path::PathBuf,
process::ExitCode,
process,
sync::{atomic::AtomicBool, Arc, Mutex},
thread,
};
Expand Down Expand Up @@ -92,10 +92,10 @@ where
let app = thread::spawn(app_exec);

if matches!(app.join(), Ok(())) {
exit_unwind(ExitCode::SUCCESS);
exit_unwind(0);
} else {
error!("App thread panic!");
exit_unwind(ExitCode::FAILURE);
exit_unwind(2);
}
});

Expand Down Expand Up @@ -132,7 +132,7 @@ where
});
drop(cid_list);

exit_unwind(ExitCode::FAILURE);
exit_unwind(1);
}
SIGTSTP => {
if has_terminal {
Expand All @@ -154,8 +154,18 @@ where
}
}

fn exit_unwind(code: ExitCode) {
std::panic::resume_unwind(Box::new(code));
struct ExitCode {
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) {
Expand Down

0 comments on commit 1865a46

Please sign in to comment.