♻️ Use session proxy when stopping systemd target
This commit is contained in:
parent
c450a9ed0d
commit
d13768607c
2 changed files with 13 additions and 3 deletions
|
|
@ -42,8 +42,8 @@ async fn main() -> Result<()> {
|
||||||
.wrap_err("failed to start systemd target")?;
|
.wrap_err("failed to start systemd target")?;
|
||||||
// Always stop the target when the process exits or panics.
|
// Always stop the target when the process exits or panics.
|
||||||
scopeguard::defer! {
|
scopeguard::defer! {
|
||||||
if let Ok(manager) = systemd_client::manager::build_blocking_proxy() {
|
if let Err(error) = systemd::stop_systemd_target() {
|
||||||
manager.stop_unit("cosmic-session.target", "replace").ok();
|
error!("failed to stop systemd target: {:?}", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let env_vars = env_rx
|
let env_vars = env_rx
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use color_eyre::{eyre::WrapErr, Result};
|
use color_eyre::{eyre::WrapErr, Result};
|
||||||
use systemd_client::manager::SystemdManagerProxy;
|
use systemd_client::manager::{SystemdManagerProxy, SystemdManagerProxyBlocking};
|
||||||
|
|
||||||
pub async fn start_systemd_target() -> Result<()> {
|
pub async fn start_systemd_target() -> Result<()> {
|
||||||
let connection = zbus::Connection::session().await?;
|
let connection = zbus::Connection::session().await?;
|
||||||
|
|
@ -14,3 +14,13 @@ pub async fn start_systemd_target() -> Result<()> {
|
||||||
.wrap_err("failed to start cosmic-session.target")?;
|
.wrap_err("failed to start cosmic-session.target")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn stop_systemd_target() -> Result<()> {
|
||||||
|
let connection = zbus::blocking::Connection::session().wrap_err("failed to connect to zbus")?;
|
||||||
|
let manager = SystemdManagerProxyBlocking::new(&connection)
|
||||||
|
.wrap_err("failed to connect to org.freedesktop.systemd1.Manager")?;
|
||||||
|
manager
|
||||||
|
.stop_unit("cosmic-session.target", "replace")
|
||||||
|
.wrap_err("failed to stop cosmic-session.target")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue