From 10997596fac76cee59090ce58276f28af107a780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Wed, 6 Apr 2022 01:52:06 +0200 Subject: [PATCH] PanicSentinel: send SIGTERM only once --- aquatic_common/src/lib.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/aquatic_common/src/lib.rs b/aquatic_common/src/lib.rs index 79b91e3..a5f25aa 100644 --- a/aquatic_common/src/lib.rs +++ b/aquatic_common/src/lib.rs @@ -55,13 +55,15 @@ pub struct PanicSentinel(Arc); 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() + ) + } } } }