Skip to main content

monitord/varlink/
manager.rs

1//! Varlink proxy for the io.systemd.Manager interface on PID 1's socket.
2//! Adapted from the interface definition in systemd's
3//! `src/core/varlink-manager.c`.
4
5use serde::{Deserialize, Serialize};
6use zlink::{proxy, ReplyError};
7
8pub const MANAGER_SOCKET_PATH: &str = "/run/systemd/io.systemd.Manager";
9
10/// Proxy trait for calling methods on the io.systemd.Manager interface.
11#[proxy("io.systemd.Manager")]
12pub trait Manager {
13    /// Describe the manager's configuration and runtime state.
14    async fn describe(&mut self) -> zlink::Result<Result<DescribeOutput, ManagerError>>;
15}
16
17/// Output parameters for the Describe method.
18///
19/// Only the runtime fields monitord consumes are declared; serde drops the
20/// rest of the (large) reply, including the whole `context` object.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct DescribeOutput {
23    pub runtime: Option<ManagerRuntime>,
24}
25
26/// Runtime state of the systemd manager.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct ManagerRuntime {
29    /// systemd version string, e.g. "262~rc3-1.fc46".
30    #[serde(rename = "Version")]
31    pub version: Option<String>,
32    /// Overall system state, e.g. "running" or "degraded".
33    #[serde(rename = "SystemState")]
34    pub system_state: Option<String>,
35}
36
37/// Errors that can occur in the io.systemd.Manager interface.
38#[derive(Debug, Clone, PartialEq, ReplyError)]
39#[zlink(interface = "io.systemd.Manager")]
40pub enum ManagerError {
41    /// The manager is refusing calls because it is being hammered.
42    RateLimitReached,
43}
44
45impl std::fmt::Display for ManagerError {
46    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47        match self {
48            ManagerError::RateLimitReached => write!(f, "Rate limit reached"),
49        }
50    }
51}
52
53impl std::error::Error for ManagerError {}