systemd: make unit_status read-only (GetUnit only, never LoadUnit)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs
This commit is contained in:
ariandClaude Sonnet 5.5 committed 2026-10-16 09:30:52 -04:00
1 parent 85af4659f1
commit 74802efd0e
7 files changed
+15 -12

No files matched your search

+8 -6
View File
@@ -286,18 +286,20 @@ impl SystemdSource for DbusSystemd {
Ok(out)
}
/// Note: for a name that is not loaded this calls `LoadUnit`, which asks
/// systemd to load the unit (a side effect, though it does not start it).
/// Read-only: uses `GetUnit`, so only units systemd already has in memory
/// are visible. `LoadUnit` is never called (it would load arbitrary
/// installed units); an unloaded unit is reported as not found.
async fn unit_status(&self, name: &str) -> Result<UnitStatus, AppError> {
validate_unit_name(name)?;
let conn = self.conn().await?;
let mgr = self.manager().await?;
let path = match mgr.get_unit(name.to_string()).await {
Ok(p) => p,
Err(e) if is_no_such_unit(&e) => mgr
.load_unit(name.to_string())
.await
.map_err(|e| self.err(e))?,
Err(e) if is_no_such_unit(&e) => {
return Err(AppError::NotFound(format!(
"unit not loaded or unknown: {name}"
)))
}
Err(e) => return Err(self.err(e)),
};
let unit = UnitProxy::builder(&conn)