interprocess/os/unix/
local_socket.rs

1//! Unix-specific local socket features.
2
3pub(crate) mod dispatch_sync;
4#[cfg(feature = "tokio")]
5pub(crate) mod dispatch_tokio;
6pub(crate) mod name_type;
7
8use crate::{local_socket::ListenerOptions, Sealed};
9pub use name_type::*;
10
11/// Unix-specific [listener options](ListenerOptions).
12#[allow(private_bounds)]
13pub trait ListenerOptionsExt: Sized + Sealed {
14    /// Sets the file mode (Unix permissions) to be applied to the socket file.
15    ///
16    /// **Not all Unix systems respect this mode when checking permissions in `connect()`!** Linux
17    /// is known to perform full permission checks for all directories along the path to the
18    /// socket file in addition to checking permissions on the socket file itself, while FreeBSD
19    /// only checks directories but not the socket file itself. If you expect your program to be
20    /// used on a wide range of Unix systems, do not rely on this as a security mechanism.
21    ///
22    /// # Implementation notes
23    /// An opportunistic `fchmod()` is performed on the socket. If the system responds with a
24    /// `EINVAL`, Interprocess concludes that `fchmod()` on sockets is not supported on the
25    /// platform, remembers this fact in an atomic global variable and falls back to a temporary
26    /// `umask` change.
27    ///
28    /// Linux is known to support `fchmod()` on Unix domain sockets, while FreeBSD is known not to.
29    ///
30    /// Note that the fallback behavior **inherently racy:** if you specify this mode as, say,
31    /// 666₈ and have another thread create a file during the critical section between the first
32    /// `umask()` call and the one performed just before returning from `.create_*()`, that file
33    /// will have mode 666₈. There is nothing Interprocess can do about this, as POSIX prescribes
34    /// the `umask` to be shared across threads.
35    #[must_use = builder_must_use!()]
36    fn mode(self, mode: libc::mode_t) -> Self;
37}
38
39impl ListenerOptionsExt for ListenerOptions<'_> {
40    #[inline(always)]
41    fn mode(mut self, mode: libc::mode_t) -> Self {
42        self.mode = Some(mode);
43        self
44    }
45}