Skip to content

Commit

Permalink
chore: Silence clippy about loop that never loops
Browse files Browse the repository at this point in the history
Do that by listening for SIGHUP, which is a signal we will never
receive, because we don't register to listen for it.

Also handle unknown signal names more gracefully, and reword the info
messages a bit.
  • Loading branch information
alcroito committed Apr 23, 2024
1 parent 6615940 commit f512f92
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions crates/dyndns/src/signal_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use color_eyre::eyre::Result;
use signal_hook::consts::signal::{SIGINT, SIGQUIT, SIGTERM};
use signal_hook::consts::signal::{SIGHUP, SIGINT, SIGQUIT, SIGTERM};
use signal_hook::consts::TERM_SIGNALS;
use signal_hook::flag;
use signal_hook::iterator::exfiltrator::WithOrigin;
use signal_hook::iterator::SignalsInfo;
use signal_hook::{consts::TERM_SIGNALS, low_level::signal_name};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::thread::JoinHandle;
Expand Down Expand Up @@ -217,16 +217,23 @@ impl AppTerminationHandler {
let mut signals_guard = self.signals.lock().expect("signals mutex poisoned");
let signals = signals_guard.as_mut().expect("signals option should exist");
for info in signals {
let killer_pid = info
let killer_pid_message = info
.process
.map(|p| format!(" by pid {}", p.pid))
.map(|p| format!(" from pid: {}", p.pid))
.unwrap_or_else(|| "".to_owned());
info!(
"Received signal {}{}",
signal_name(info.signal).expect("Empty signal name"),
killer_pid
);

let signal_name = signal_hook::low_level::signal_name(info.signal)
.map(|s| s.to_owned())
.unwrap_or_else(|| {
info!("Can't find human readable name for signal: {}", info.signal);
info.signal.to_string()
});

info!("Received signal: {}{}", signal_name, killer_pid_message);
match info.signal {
SIGHUP => {
info!("Ignoring signal because config reloading is not yet supported")
}
SIGTERM | SIGQUIT | SIGINT => {
assert!(TERM_SIGNALS.contains(&info.signal));
info!("Starting process termination due to received signal");
Expand Down

0 comments on commit f512f92

Please sign in to comment.