From d6741d578621a1ee33a45332acf8a54ccf1537bf Mon Sep 17 00:00:00 2001 From: Joshua Ferguson Date: Fri, 21 Jun 2024 16:41:59 -0400 Subject: [PATCH] logged in and confirmed scopes worked --- src/main.rs | 3 +-- src/systemd.rs | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index cb6710a..d707856 100644 --- a/src/main.rs +++ b/src/main.rs @@ -419,9 +419,8 @@ async fn start_component( //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(&format!("{cmd}.scope"), vec![pids]) + spawn_scope(cmd.to_string(), vec![pids]) .await - .unwrap(); } process_manager.get_pid(key).await.unwrap(); } diff --git a/src/systemd.rs b/src/systemd.rs index d6041df..4727742 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -48,11 +48,17 @@ pub fn is_systemd_used() -> &'static bool { } ///Spawn a systemd scope unit with the given name and PIDs. -pub async fn spawn_scope(scope_name: &str, pids: Vec) -> zbus::Result<()> { - let connection = Connection::session().await?; - let systemd_manager = SystemdManagerProxy::new(&connection).await?; - let pids = OwnedValue::try_from(Value::Array(Array::from(pids)))?; +pub async fn spawn_scope(mut scope_name: String, pids: Vec) { + let connection = Connection::session().await.unwrap(); + let systemd_manager = SystemdManagerProxy::new(&connection).await.unwrap(); + let pids = OwnedValue::try_from(Array::from(pids)).unwrap(); let properties = vec![(String::from("PIDs"), pids)]; + if scope_name.starts_with("/") { + // use the last component of the path as the unit name + scope_name = scope_name.rsplit('/').next().unwrap().to_string(); + } + scope_name = format!("{}.scope", scope_name); + info!("scope name is {}", scope_name); systemd_manager .start_transient_unit( scope_name.to_string(), @@ -60,9 +66,8 @@ pub async fn spawn_scope(scope_name: &str, pids: Vec) -> zbus::Result<()> { properties, Vec::new(), ) - .await?; - - Ok(()) + .await + .unwrap(); } /// run a command, but log errors instead of returning them or panicking