From ea2c6901897d73bd1a263f2fdcccd8b42d5b8bb0 Mon Sep 17 00:00:00 2001 From: crabman Date: Wed, 14 Feb 2024 20:44:25 +0100 Subject: [PATCH] exclude non linux/macos targets from compiling ShutdownSignal --- server-cli/src/main.rs | 13 +++++++++---- server-cli/src/settings.rs | 24 +++++++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index 49eefc712c..a7c1229bf8 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -69,13 +69,18 @@ fn main() -> io::Result<()> { #[cfg(any(target_os = "linux", target_os = "macos"))] { for signal in &settings.shutdown_signals { - let _ = signal_hook::flag::register( - *signal as core::ffi::c_int, - Arc::clone(&shutdown_signal), - ); + let _ = signal_hook::flag::register(signal.to_signal(), Arc::clone(&shutdown_signal)); } } + #[cfg(not(any(target_os = "linux", target_os = "macos")))] + if !settings.shutdown_signals.is_empty() { + tracing::warn!( + "Server configuration contains shutdown signals, but your platform does not support \ + them" + ); + } + // Determine folder to save server data in let server_data_dir = { let mut path = common_base::userdata_dir_workspace!(); diff --git a/server-cli/src/settings.rs b/server-cli/src/settings.rs index 2b24aa4bf0..c834047ca4 100644 --- a/server-cli/src/settings.rs +++ b/server-cli/src/settings.rs @@ -7,12 +7,22 @@ use std::{ use tracing::warn; #[derive(Clone, Copy, Debug, Serialize, Deserialize)] -#[repr(i32)] #[allow(clippy::upper_case_acronyms)] pub enum ShutdownSignal { - SIGUSR1 = signal_hook::consts::SIGUSR1, - SIGUSR2 = signal_hook::consts::SIGUSR2, - SIGTERM = signal_hook::consts::SIGTERM, + SIGUSR1, + SIGUSR2, + SIGTERM, +} + +impl ShutdownSignal { + #[cfg(any(target_os = "linux", target_os = "macos"))] + pub fn to_signal(self) -> core::ffi::c_int { + match self { + Self::SIGUSR1 => signal_hook::consts::SIGUSR1, + Self::SIGUSR2 => signal_hook::consts::SIGUSR2, + Self::SIGTERM => signal_hook::consts::SIGTERM, + } + } } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -34,7 +44,11 @@ impl Default for Settings { update_shutdown_message: "The server is restarting for an update".to_owned(), web_address: SocketAddr::from((Ipv4Addr::LOCALHOST, 14005)), web_chat_secret: None, - shutdown_signals: vec![ShutdownSignal::SIGUSR1], + shutdown_signals: if cfg!(any(target_os = "linux", target_os = "macos")) { + vec![ShutdownSignal::SIGUSR1] + } else { + Vec::new() + }, } } }