exclude non linux/macos targets from compiling ShutdownSignal

This commit is contained in:
crabman 2024-02-14 20:44:25 +01:00
parent 68ba2b4e1e
commit ea2c690189
No known key found for this signature in database
2 changed files with 28 additions and 9 deletions

View File

@ -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!();

View File

@ -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()
},
}
}
}