systemd: Do not check systemd version

The systemd version is purely informational and should not be parsed, as
documented in the [1]. In practice, systemd version has different formats
on OpenShift and Ubuntu.

This commit skips the version check and allows all operations. The errors
will be thrown from dbus when performing unsupported operations on obsolete
versions of systemd.

1: https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
Xuewei Niu
2025-08-07 10:46:54 +08:00
parent 5d74a1dfc9
commit c49bee218f
8 changed files with 16 additions and 92 deletions

View File

@@ -72,22 +72,11 @@ pub mod tests {
child
}
pub fn systemd_version() -> Option<usize> {
pub fn systemd_version() -> Option<String> {
let output = Command::new("systemd").arg("--version").output().ok()?; // Return None if command execution fails
if !output.status.success() {
return None;
}
let stdout = String::from_utf8_lossy(&output.stdout);
// The first line is typically like "systemd 254 (254.5-1-arch)"
let first_line = stdout.lines().next()?;
let mut words = first_line.split_whitespace();
words.next()?; // Skip the "systemd" word
let version_str = words.next()?; // The version number as string
version_str.parse::<usize>().ok()
Some(String::from_utf8_lossy(&output.stdout).to_string())
}
}