logged in and confirmed scopes worked

This commit is contained in:
Joshua Ferguson 2024-06-21 16:41:59 -04:00 committed by Ashley Wulber
parent 93a9524996
commit d6741d5786
2 changed files with 13 additions and 9 deletions

View file

@ -419,9 +419,8 @@ async fn start_component(
//currently pid is optional hence the double unwrap //currently pid is optional hence the double unwrap
let pids = process_manager.get_pid(key).await.unwrap().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 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 .await
.unwrap();
} }
process_manager.get_pid(key).await.unwrap(); process_manager.get_pid(key).await.unwrap();
} }

View file

@ -48,11 +48,17 @@ pub fn is_systemd_used() -> &'static bool {
} }
///Spawn a systemd scope unit with the given name and PIDs. ///Spawn a systemd scope unit with the given name and PIDs.
pub async fn spawn_scope(scope_name: &str, pids: Vec<u32>) -> zbus::Result<()> { pub async fn spawn_scope(mut scope_name: String, pids: Vec<u32>) {
let connection = Connection::session().await?; let connection = Connection::session().await.unwrap();
let systemd_manager = SystemdManagerProxy::new(&connection).await?; let systemd_manager = SystemdManagerProxy::new(&connection).await.unwrap();
let pids = OwnedValue::try_from(Value::Array(Array::from(pids)))?; let pids = OwnedValue::try_from(Array::from(pids)).unwrap();
let properties = vec![(String::from("PIDs"), pids)]; 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 systemd_manager
.start_transient_unit( .start_transient_unit(
scope_name.to_string(), scope_name.to_string(),
@ -60,9 +66,8 @@ pub async fn spawn_scope(scope_name: &str, pids: Vec<u32>) -> zbus::Result<()> {
properties, properties,
Vec::new(), Vec::new(),
) )
.await?; .await
.unwrap();
Ok(())
} }
/// run a command, but log errors instead of returning them or panicking /// run a command, but log errors instead of returning them or panicking