PanicSentinel: send SIGTERM only once

This commit is contained in:
Joakim Frostegård 2022-04-06 01:52:06 +02:00
parent b61b136b0c
commit 10997596fa

View file

@ -55,13 +55,15 @@ pub struct PanicSentinel(Arc<AtomicBool>);
impl Drop for PanicSentinel {
fn drop(&mut self) {
self.0.store(true, Ordering::SeqCst);
let already_triggered = self.0.fetch_or(true, Ordering::SeqCst);
if unsafe { libc::raise(15) } == -1 {
panic!(
"Could not raise SIGTERM: {:#}",
::std::io::Error::last_os_error()
)
if !already_triggered {
if unsafe { libc::raise(15) } == -1 {
panic!(
"Could not raise SIGTERM: {:#}",
::std::io::Error::last_os_error()
)
}
}
}
}