From 4df7261a6ccf621d952a92b117aa58bc3d63d6d5 Mon Sep 17 00:00:00 2001 From: Daniel Huang Date: Wed, 21 Aug 2024 13:14:36 -0400 Subject: [PATCH] Simplify `is_systemd_used` --- src/systemd.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/systemd.rs b/src/systemd.rs index 9d617d5..6ef02e4 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -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 = 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")]