Mercurial > crates > systemd-socket
diff src/error.rs @ 24:1941e9d9819c
Fix unsound manipulation of env vars
Modifying env vars in multi-threaded process is unsound but this crate
was neither checking the number of threads nor mark its functions as
`unsafe`. This change fixes it by both adding a check and adding an
`unsafe` function that can bypass that check if needed.
author | Martin Habovstiak <martin.habovstiak@gmail.com> |
---|---|
date | Fri, 28 Feb 2025 13:52:31 +0100 |
parents | f6334887e3c8 |
children | cfef4593e207 |
line wrap: on
line diff
--- a/src/error.rs Sat Jul 13 15:14:32 2024 +0200 +++ b/src/error.rs Fri Feb 28 13:52:31 2025 +0100 @@ -4,8 +4,33 @@ use thiserror::Error; +use std::fmt; use std::io; +/// Error returned when the library initialization fails. +#[derive(Debug)] +pub struct InitError(pub(crate) InitErrorInner); + +#[cfg(all(target_os = "linux", feature = "enable_systemd"))] +type InitErrorInner = super::systemd_sockets::InitError; + +#[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] +type InitErrorInner = std::convert::Infallible; + +impl fmt::Display for InitError { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(&self.0, f) + } +} + +impl std::error::Error for InitError { + #[inline] + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + self.0.source() + } +} + /// Error that can occur during parsing of `SocketAddr` from a string /// /// This encapsulates possible errors that can occur when parsing the input.