From e39d885faeae8618fdd48f286ed34acce4fcaf35 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Fri, 16 Oct 2026 08:57:21 -0400 Subject: [PATCH] DbusSystemd: drop unused config/shutdown, derive Default Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs --- examples/systemd_dump.rs | 4 +--- src/sources/systemd.rs | 18 ++++-------------- src/state.rs | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/examples/systemd_dump.rs b/examples/systemd_dump.rs index bb3265c..12d32ed 100644 --- a/examples/systemd_dump.rs +++ b/examples/systemd_dump.rs @@ -1,17 +1,15 @@ //! Dump systemd state from the live system bus as JSON. //! Usage: cargo run --example systemd_dump [unit-name] -use skyg_linux_tracker::config::Config; use skyg_linux_tracker::sources::systemd::DbusSystemd; use skyg_linux_tracker::sources::SystemdSource; -use tokio_util::sync::CancellationToken; #[tokio::main] async fn main() -> Result<(), Box> { let unit = std::env::args() .nth(1) .unwrap_or_else(|| "dbus.service".to_string()); - let src = DbusSystemd::new(&Config::default(), CancellationToken::new()); + let src = DbusSystemd::default(); let out = serde_json::json!({ "units": src.list_units(None).await?, "failed": src.list_units(Some("failed")).await?, diff --git a/src/sources/systemd.rs b/src/sources/systemd.rs index 03f002f..c72a09e 100644 --- a/src/sources/systemd.rs +++ b/src/sources/systemd.rs @@ -1,4 +1,4 @@ -//! systemd source over D-Bus (WS-A). Every call hits the bus live; only the +//! systemd source over D-Bus. Every call hits the bus live; only the //! connection is cached, and it is opened lazily on first use. A connection //! found dead is dropped so the next call reconnects. @@ -6,13 +6,11 @@ use std::sync::Mutex; use async_trait::async_trait; use jiff::Timestamp; -use tokio_util::sync::CancellationToken; use zbus::zvariant::OwnedObjectPath; use zbus::Connection; use zbus_systemd::systemd1::{ManagerProxy, ServiceProxy, TimerProxy, UnitProxy}; use super::{SystemdSource, TimerInfo, UnitStatus, UnitSummary}; -use crate::config::Config; use crate::error::AppError; const NO_SUCH_UNIT: &str = "org.freedesktop.systemd1.NoSuchUnit"; @@ -90,23 +88,15 @@ type UnitRow = ( OwnedObjectPath, ); +/// Does not touch the bus on construction; the connection is made on first +/// use and failures map to `AppError::Unavailable`. +#[derive(Default)] pub struct DbusSystemd { /// Cached bus connection; cleared when found dead. conn: Mutex>, - #[allow(dead_code)] - shutdown: CancellationToken, } impl DbusSystemd { - /// Does not touch the bus; the connection is made on first use and - /// failures map to `AppError::Unavailable`. - pub fn new(_config: &Config, shutdown: CancellationToken) -> Self { - Self { - conn: Mutex::new(None), - shutdown, - } - } - async fn conn(&self) -> Result { if let Some(c) = self.conn.lock().unwrap().clone() { return Ok(c); diff --git a/src/state.rs b/src/state.rs index caa85d9..ed1ad2c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -27,7 +27,7 @@ impl AppState { pub fn live(config: Config, db: Option, shutdown: CancellationToken) -> Self { use crate::sources::{docker::BollardDocker, journal::SdJournal, systemd::DbusSystemd}; Self { - systemd: Arc::new(DbusSystemd::new(&config, shutdown.clone())), + systemd: Arc::new(DbusSystemd::default()), journal: Arc::new(SdJournal::new(&config, shutdown.clone())), docker: Arc::new(BollardDocker::new(&config, shutdown.clone())), config: Arc::new(config),