From 5384232eec4dff669cd2bb68ee93c34b6b63c78c Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 12 Aug 2026 02:51:50 +0000 Subject: Collect services from all systemd targets --- src/manifest.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/manifest.rs b/src/manifest.rs index b3e489d..3c34ade 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -170,15 +170,26 @@ fn collect_files(rootfs: &Path) -> Result> { } fn collect_services(rootfs: &Path) -> Result> { - let wants = rootfs.join("etc/systemd/system/multi-user.target.wants"); - if !wants.exists() { + let system = rootfs.join("etc/systemd/system"); + if !system.is_dir() { return Ok(Vec::new()); } let mut services = Vec::new(); - for entry in fs::read_dir(&wants).with_context(|| format!("read service state directory {}", wants.display()))? { - let entry = entry?; - let name = entry.file_name().into_string().map_err(|_| anyhow::anyhow!("non-UTF-8 service name in {}", wants.display()))?; - if entry.file_type()?.is_symlink() && name.ends_with(".service") { + for entry in WalkDir::new(&system).follow_links(false).min_depth(2) { + let entry = entry.with_context(|| format!("walk service state directory {}", system.display()))?; + let parent_is_wants_directory = entry + .path() + .parent() + .and_then(Path::file_name) + .is_some_and(|name| name.to_string_lossy().ends_with(".target.wants")); + if !parent_is_wants_directory || !entry.file_type().is_symlink() { + continue; + } + let name = entry + .file_name() + .to_str() + .ok_or_else(|| anyhow::anyhow!("non-UTF-8 service name in {}", entry.path().display()))?; + if name.ends_with(".service") { services.push(ServiceRecord::new(name, true)); } } -- cgit v1.2.3