# WS-A — systemd source | Field | Value | |---|---| | Status | Done | | Owner | — | | Phase | 1 (parallel) | | Depends on | P0 | | Blocks | WS-E, WS-F, WS-G (to finish) | | Owned files | `src/sources/systemd.rs`, `examples/systemd_dump.rs` | ## Goal Implement `SystemdSource` over D-Bus with `zbus_systemd`. Every call hits the bus live, with no caching. ## Tasks Tick these in [`TODO.md`](../../TODO.md). - **A1** Create one `zbus::Connection::system()` at construction and share `ManagerProxy`. - **A2** `list_units(state: Option<…>)`. Use `ListUnitsFiltered(states)` when a state is given, otherwise `ListUnits`. Map the tuple to `UnitSummary` (name, description, load/active/sub state). - **A3** `list_timers()`. The Manager has no `ListTimers` method (review R1). Call `ListUnitsByPatterns([], ["*.timer"])`, then for each timer read `TimerProxy`: `NextElapseUSecRealtime`, `LastTriggerUSec`, `Unit` (the triggered unit). Convert µs since epoch to RFC3339. `0` or `u64::MAX` means `None`. - **A4** `unit_status(name)`. Try `GetUnit(name)` first, falling back to `LoadUnit` only on `NoSuchUnit`. The fallback lets inactive unloaded units still report without side effects on loaded ones. - `Unit` props: `ActiveState`, `SubState`, `LoadState`, `Description`, `ActiveEnterTimestamp`, `FragmentPath`. - `Service` props, only when the name ends in `.service`: `ExecMainStatus`, `NRestarts`, `MainPID`. - **A5** Validate names against systemd's charset (`[A-Za-z0-9:_.@\-\\]`, max 255) and return `BadRequest`. Map D-Bus `NoSuchUnit` to `NotFound`. Map bus connection failure to `Unavailable`. - **A6** `examples/systemd_dump.rs` prints JSON for units, failed units, timers and one unit's status. - **A7** Unit tests for µs-to-RFC3339 conversion, sentinel handling and tuple mapping. ## Done when - `cargo run --example systemd_dump` prints sane JSON on a real host. Timers show next elapse times that match `systemctl list-timers`. - `unit_status("nonexistent.service")` returns `NotFound` and `unit_status("../etc")` returns `BadRequest`. ## Notes - Property reads cost one D-Bus round-trip each. Fetch with `GetAll` where zbus_systemd exposes it, or `join!` the reads. - Unprivileged reads on the system bus are allowed. No polkit involvement is needed for these calls. ## Log - 2026-10-15: Card created. - 2026-10-15: Implemented on branch `ws-a/systemd-source`. Gates pass; example verified on live bus (timers match `systemctl list-timers`, NotFound/BadRequest verified). Beyond spec: LoadUnit result with load_state `not-found` also maps to NotFound; `unit_file_state`/`active_exit_time` populated.