Mercurial > crates > systemd-socket
diff src/lib.rs @ 16:bc76507dd878
Fixed conditional compilation based on OS
A mistake was causing systemd to never enable and the tests were too
clever to detect that. Not sure what to do with it.
author | Martin Habovstiak <martin.habovstiak@gmail.com> |
---|---|
date | Tue, 22 Dec 2020 13:58:47 +0100 |
parents | f740dadd2948 |
children | dfb727367934 |
line wrap: on
line diff
--- a/src/lib.rs Tue Dec 22 13:56:56 2020 +0100 +++ b/src/lib.rs Tue Dec 22 13:58:47 2020 +0100 @@ -68,10 +68,10 @@ use crate::error::*; use crate::resolv_addr::ResolvAddr; -#[cfg(not(all(linux, feature = "enable_systemd")))] +#[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] use std::convert::Infallible as Never; -#[cfg(all(linux, feature = "enable_systemd"))] +#[cfg(all(target_os = "linux", feature = "enable_systemd"))] pub(crate) mod systemd_sockets { use std::fmt; use std::sync::Mutex; @@ -227,7 +227,7 @@ // rules. fn try_from_generic<'a, T>(string: T) -> Result<Self, ParseError> where T: 'a + std::ops::Deref<Target=str> + Into<String> { if string.starts_with(SYSTEMD_PREFIX) { - #[cfg(all(linux, feature = "enable_systemd"))] + #[cfg(all(target_os = "linux", feature = "enable_systemd"))] { let name_len = string.len() - SYSTEMD_PREFIX.len(); match string[SYSTEMD_PREFIX.len()..].chars().enumerate().find(|(_, c)| !c.is_ascii() || *c < ' ' || *c == ':') { @@ -236,7 +236,7 @@ Some((pos, c)) => Err(ParseErrorInner::InvalidCharacter { string: string.into(), c, pos, }.into()), } } - #[cfg(not(all(linux, feature = "enable_systemd")))] + #[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] { Err(ParseErrorInner::SystemdUnsupported(string.into()).into()) } @@ -248,7 +248,7 @@ } } - #[cfg(all(linux, feature = "enable_systemd"))] + #[cfg(all(target_os = "linux", feature = "enable_systemd"))] fn get_systemd(socket_name: String) -> Result<(std::net::TcpListener, SocketAddrInner), BindError> { use libsystemd::activation::IsType; use std::os::unix::io::{FromRawFd, IntoRawFd}; @@ -268,8 +268,8 @@ } // This approach makes the rest of the code much simpler as it doesn't require sprinkling it - // with #[cfg(all(linux, feature = "enable_systemd"))] yet still statically guarantees it won't execute. - #[cfg(not(linux))] + // with #[cfg(all(target_os = "linux", feature = "enable_systemd"))] yet still statically guarantees it won't execute. + #[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] fn get_systemd(socket_name: Never) -> Result<(std::net::TcpListener, SocketAddrInner), BindError> { match socket_name {} } @@ -300,9 +300,9 @@ enum SocketAddrInner { Ordinary(std::net::SocketAddr), WithHostname(resolv_addr::ResolvAddr), - #[cfg(all(linux, feature = "enable_systemd"))] + #[cfg(all(target_os = "linux", feature = "enable_systemd"))] Systemd(String), - #[cfg(not(all(linux, feature = "enable_systemd")))] + #[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] #[allow(dead_code)] Systemd(Never), } @@ -404,13 +404,13 @@ } #[test] - #[cfg(all(linux, feature = "enable_systemd"))] + #[cfg(all(target_os = "linux", feature = "enable_systemd"))] fn parse_systemd() { assert_eq!("systemd://foo".parse::<SocketAddr>().unwrap().0, SocketAddrInner::Systemd("systemd://foo".to_owned())); } #[test] - #[cfg(not(all(linux, feature = "enable_systemd")))] + #[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] #[should_panic] fn parse_systemd() { "systemd://foo".parse::<SocketAddr>().unwrap();