Simplify is_systemd_used
This commit is contained in:
parent
c3de3d24dd
commit
4df7261a6c
1 changed files with 2 additions and 15 deletions
|
|
@ -1,5 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
|
|
@ -33,21 +34,7 @@ pub fn stop_systemd_target() {
|
|||
///Determine if systemd is used as the init system. This should work on all linux distributions.
|
||||
pub fn is_systemd_used() -> &'static bool {
|
||||
static IS_SYSTEMD_USED: OnceLock<bool> = OnceLock::new();
|
||||
IS_SYSTEMD_USED.get_or_init(|| {
|
||||
match Command::new("ls").args(["/run/systemd/system"]).output() {
|
||||
Ok(output) => {
|
||||
if output.status.success() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
warn!("unable to check if systemd is used: {}", error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
IS_SYSTEMD_USED.get_or_init(|| Path::new("/run/systemd/system").exists())
|
||||
}
|
||||
|
||||
#[cfg(feature = "systemd")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue