diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-12 02:51:50 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-12 02:51:50 +0000 |
| commit | 5384232eec4dff669cd2bb68ee93c34b6b63c78c (patch) | |
| tree | de303d2741202c98ebc4b11af09ba1aab690eb6d /src | |
| parent | 450a5b27e101e7b40cd2d035056c4141e9477f6a (diff) | |
Collect services from all systemd targets
Diffstat (limited to 'src')
| -rw-r--r-- | src/manifest.rs | 23 |
1 files changed, 17 insertions, 6 deletions
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<Vec<FileRecord>> { } fn collect_services(rootfs: &Path) -> Result<Vec<ServiceRecord>> { - 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)); } } |