♻️ 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")?;
|
||||
// Always stop the target when the process exits or panics.
|
||||
scopeguard::defer! {
|
||||
if let Ok(manager) = systemd_client::manager::build_blocking_proxy() {
|
||||
manager.stop_unit("cosmic-session.target", "replace").ok();
|
||||
if let Err(error) = systemd::stop_systemd_target() {
|
||||
error!("failed to stop systemd target: {:?}", error);
|
||||
}
|
||||
}
|
||||
let env_vars = env_rx
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use color_eyre::{eyre::WrapErr, Result};
|
||||
use systemd_client::manager::SystemdManagerProxy;
|
||||
use systemd_client::manager::{SystemdManagerProxy, SystemdManagerProxyBlocking};
|
||||
|
||||
pub async fn start_systemd_target() -> Result<()> {
|
||||
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")?;
|
||||
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