diff --git a/varde-daemon/Cargo.toml b/varde-daemon/Cargo.toml index 32dbcb2..da5e962 100644 --- a/varde-daemon/Cargo.toml +++ b/varde-daemon/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true [[bin]] name = "varde-daemon" path = "src/main.rs" +required-features = ["socket-api"] [dependencies] varde-proto = { workspace = true } @@ -42,8 +43,12 @@ tracing-subscriber = { workspace = true } [features] # Metered-connection detection via NetworkManager over D-Bus. On by # default; disable for systems without D-Bus (they run as unmetered). -default = ["metered"] +default = ["metered", "socket-api"] metered = ["dep:zbus"] +# The unix-socket API server, systemd socket activation, and signal +# handling. On by default; disable to embed the daemon core in-process +# on platforms without a daemon model (iOS — ADR-0012 in redoal). +socket-api = [] [dev-dependencies] tempfile = "3" diff --git a/varde-daemon/src/lib.rs b/varde-daemon/src/lib.rs index 07a2c0f..4830f19 100644 --- a/varde-daemon/src/lib.rs +++ b/varde-daemon/src/lib.rs @@ -9,16 +9,19 @@ pub mod discovery; pub mod dscp; pub mod meta; pub mod metered; +#[cfg(feature = "socket-api")] pub mod server; pub mod shaped; pub mod store; pub mod transfer; +#[cfg(feature = "socket-api")] use anyhow::Result; /// Run a daemon with the given config until the future is dropped or the /// listener fails. The socket is bound before the accept loop starts, so /// once this future has been polled the socket path exists. +#[cfg(feature = "socket-api")] pub async fn run(config: config::Config) -> Result<()> { let socket_path = config.socket_path.clone(); let daemon = daemon::Daemon::open(config).await?; diff --git a/varde-daemon/src/server.rs b/varde-daemon/src/server.rs index 47a8882..ee45896 100644 --- a/varde-daemon/src/server.rs +++ b/varde-daemon/src/server.rs @@ -49,9 +49,19 @@ pub fn notify_ready() { let socket = std::os::unix::net::UnixDatagram::unbound()?; let bytes = path.as_encoded_bytes(); if let Some(name) = bytes.strip_prefix(b"@") { - use std::os::linux::net::SocketAddrExt; - let addr = std::os::unix::net::SocketAddr::from_abstract_name(name)?; - socket.send_to_addr(b"READY=1", &addr)?; + // Abstract socket names are Linux-only, like systemd itself; + // elsewhere an @-prefixed NOTIFY_SOCKET can only be ignored. + #[cfg(target_os = "linux")] + { + use std::os::linux::net::SocketAddrExt; + let addr = std::os::unix::net::SocketAddr::from_abstract_name(name)?; + socket.send_to_addr(b"READY=1", &addr)?; + } + #[cfg(not(target_os = "linux"))] + { + let _ = name; + debug!("abstract NOTIFY_SOCKET unsupported on this platform"); + } } else { socket.send_to(b"READY=1", &path)?; }