From b096107f81368b365c8f4d0804fc2fc2bbfe4573 Mon Sep 17 00:00:00 2001 From: Joshua Ferguson Date: Fri, 21 Jun 2024 18:03:30 -0400 Subject: [PATCH] trying to figure out the ideal way to feature gate systemd --- src/main.rs | 28 +++++++++++++++------------- src/systemd.rs | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 05b1bce..817495d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -415,18 +415,20 @@ async fn start_component( ) .await .unwrap_or_else(|_| panic!("failed to start {}", cmd)); - if *is_systemd_used() { - //currently pid is optional hence the double unwrap - let pids = process_manager.get_pid(key).await.unwrap().unwrap(); - //spawn_scope takes a vec of pids in case we want to spawn a scope for multiple processes - spawn_scope(cmd.to_string(), vec![pids]) - .await - .unwrap_or_else(|err| { - warn!( - "Failed to spawn scope for {}. Creating transient unit failed with {}", - cmd, err - ); - }); + #[cfg(feature = "systemd")] + { + if *is_systemd_used() { + //currently pid is optional hence the double unwrap + let pids = process_manager.get_pid(key).await.unwrap().unwrap(); + //spawn_scope takes a vec of pids in case we want to spawn a scope for multiple processes + spawn_scope(cmd.to_string(), vec![pids]) + .await + .unwrap_or_else(|err| { + warn!( + "Failed to spawn scope for {}. Creating transient unit failed with {}", + cmd, err + ); + }); + } } - process_manager.get_pid(key).await.unwrap(); } diff --git a/src/systemd.rs b/src/systemd.rs index f5f8f61..be101c6 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -47,6 +47,7 @@ pub fn is_systemd_used() -> &'static bool { ) } +#[cfg(feature = "systemd")] ///Spawn a systemd scope unit with the given name and PIDs. pub async fn spawn_scope(mut command: String, pids: Vec) -> Result<(), zbus::Error> { let connection = Connection::session().await?;