2.6 KiB
2.6 KiB
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.
- A1 Create one
zbus::Connection::system()at construction and shareManagerProxy. - A2
list_units(state: Option<…>). UseListUnitsFiltered(states)when a state is given, otherwiseListUnits. Map the tuple toUnitSummary(name, description, load/active/sub state). - A3
list_timers(). The Manager has noListTimersmethod (review R1). CallListUnitsByPatterns([], ["*.timer"]), then for each timer readTimerProxy:NextElapseUSecRealtime,LastTriggerUSec,Unit(the triggered unit). Convert µs since epoch to RFC3339.0oru64::MAXmeansNone. - A4
unit_status(name). TryGetUnit(name)first, falling back toLoadUnitonly onNoSuchUnit. The fallback lets inactive unloaded units still report without side effects on loaded ones.Unitprops:ActiveState,SubState,LoadState,Description,ActiveEnterTimestamp,FragmentPath.Serviceprops, only when the name ends in.service:ExecMainStatus,NRestarts,MainPID.
- A5 Validate names against systemd's charset (
[A-Za-z0-9:_.@\-\\], max 255) and returnBadRequest. Map D-BusNoSuchUnittoNotFound. Map bus connection failure toUnavailable. - A6
examples/systemd_dump.rsprints 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_dumpprints sane JSON on a real host. Timers show next elapse times that matchsystemctl list-timers.unit_status("nonexistent.service")returnsNotFoundandunit_status("../etc")returnsBadRequest.
Notes
- Property reads cost one D-Bus round-trip each. Fetch with
GetAllwhere zbus_systemd exposes it, orjoin!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 matchsystemctl list-timers, NotFound/BadRequest verified). Beyond spec: LoadUnit result with load_statenot-foundalso maps to NotFound;unit_file_state/active_exit_timepopulated.