added zbus_systemd as an optional dependency
This commit is contained in:
parent
e1a0048f33
commit
93a9524996
3 changed files with 129 additions and 82 deletions
|
|
@ -6,6 +6,9 @@ use std::sync::OnceLock;
|
|||
use zbus::zvariant::{Array, OwnedValue};
|
||||
use zbus::{proxy, zvariant::Value, Connection};
|
||||
|
||||
#[cfg(feature = "systemd")]
|
||||
use zbus_systemd::systemd1::ManagerProxy as SystemdManagerProxy;
|
||||
|
||||
pub async fn set_systemd_environment(key: &str, value: &str) {
|
||||
run_optional_command(
|
||||
"systemctl",
|
||||
|
|
@ -44,31 +47,19 @@ pub fn is_systemd_used() -> &'static bool {
|
|||
)
|
||||
}
|
||||
|
||||
#[proxy(
|
||||
name = "org.freedesktop.systemd1.Manager",
|
||||
default_service = "org.freedesktop.systemd1",
|
||||
default_path = "/org/freedesktop/systemd1"
|
||||
)]
|
||||
trait SystemdManager<'a> {
|
||||
fn start_transient_unit<'a>(
|
||||
&self,
|
||||
name: &str,
|
||||
mode: &str,
|
||||
properties: Vec<(String, Value<'a>)>,
|
||||
//This is based on the systemd-zbus implementation, however according to the spec this should be empty
|
||||
//see: https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html#:~:text=aux%20is%20currently%20unused
|
||||
aux: Vec<(String, Vec<(String, Value<'a>)>)>,
|
||||
) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
///Spawn a systemd scope unit with the given name and PIDs.
|
||||
pub async fn spawn_scope(scope_name: &str, pids: Vec<u32>) -> zbus::Result<()> {
|
||||
let connection = Connection::session().await?;
|
||||
let systemd_manager = SystemdManagerProxy::new(&connection).await?;
|
||||
|
||||
let properties = vec![(String::from("PIDs"), Value::Array(Array::from(pids)))];
|
||||
let pids = OwnedValue::try_from(Value::Array(Array::from(pids)))?;
|
||||
let properties = vec![(String::from("PIDs"), pids)];
|
||||
systemd_manager
|
||||
.start_transient_unit(scope_name, "fail", properties, Vec::new())
|
||||
.start_transient_unit(
|
||||
scope_name.to_string(),
|
||||
String::from("fail"),
|
||||
properties,
|
||||
Vec::new(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue