pub struct UnitLookup { /* private fields */ }Expand description
A connection to PID 1’s unit API that remembers what it has already asked.
Built once per collection cycle. The cache matters because the same unit can
be wanted by more than one caller in a cycle — a .service can be both in
[services] and the target of a tracked timer — and a miss costs a round
trip to PID 1, which serves varlink requests one at a time.
Implementations§
Source§impl UnitLookup
impl UnitLookup
pub async fn connect(socket_path: &str) -> Result<Self>
Sourcepub async fn get(&mut self, name: &str) -> Result<Option<&ListOutput>>
pub async fn get(&mut self, name: &str) -> Result<Option<&ListOutput>>
Look a unit up, returning Ok(None) if systemd does not know it.
A transport or protocol failure is an error rather than None, so the
caller can fall back to D-Bus for the whole phase. Collapsing the two
would leave service stats silently empty on a broken socket while
reporting success.
A unit that is genuinely absent is cached as absent: the answer will not change within a cycle, and re-asking would cost another round trip.