libsystemd_sys/lib.rs
1//! Low-level bindings to libsystemd (and similar) libraries
2//!
3//! Items in this module correspond to systemd functions/types that are documented by the systemd
4//! (`sd_*`) man pages.
5
6#![warn(rust_2018_idioms)]
7
8pub use libc::{clockid_t, gid_t, iovec, pid_t, siginfo_t, signalfd_siginfo, size_t, uid_t};
9pub use std::os::raw::{c_char, c_int, c_uint, c_void};
10
11pub mod daemon;
12pub mod event;
13pub mod id128;
14#[cfg(feature = "journal")]
15pub mod journal;
16pub mod login;
17
18/// Helper type to mark functions systemd functions that promise not to modify the underlying iovec
19/// data. There is no corresponding type in libc, so their function signatures take *const iovec,
20/// which technically allow iov_base to be modified. However, const_iovec provides the same ABI, so
21/// it can be used to make the function interface easier to work with.
22#[repr(C)]
23pub struct const_iovec {
24 pub iov_base: *const c_void,
25 pub iov_len: size_t,
26}
27
28impl const_iovec {
29 ///
30 /// # Safety
31 ///
32 /// Lifetime of `arg` must be long enough to cover future dereferences of the internal
33 /// `Self::iov_base` pointer.
34 pub unsafe fn from_str<T>(arg: T) -> Self
35 where
36 T: AsRef<str>,
37 {
38 const_iovec {
39 iov_base: arg.as_ref().as_ptr() as *const c_void,
40 iov_len: arg.as_ref().len() as size_t,
41 }
42 }
43}
44
45#[cfg(feature = "bus")]
46pub mod bus;