DbusSystemd: drop unused config/shutdown, derive Default
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs
This commit is contained in:
1 parent
d022ebeae5
commit
e39d885fae
3 files changed
+6
-18
No files matched your search
@@ -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<dyn std::error::Error>> {
|
||||
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?,
|
||||
|
||||
+4
-14
@@ -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<Option<Connection>>,
|
||||
#[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<Connection, AppError> {
|
||||
if let Some(c) = self.conn.lock().unwrap().clone() {
|
||||
return Ok(c);
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ impl AppState {
|
||||
pub fn live(config: Config, db: Option<SqlitePool>, 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),
|
||||
|
||||
Reference in new issue
Block a user