fix: prevent session from exiting
This commit is contained in:
parent
30ce09f54a
commit
e1a174f61d
4 changed files with 200 additions and 145 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -207,7 +207,7 @@ async fn main() -> Result<()> {
|
|||
.expect("failed to start settings daemon");
|
||||
|
||||
let (exit_tx, exit_rx) = oneshot::channel();
|
||||
let _ = ConnectionBuilder::session()?
|
||||
let _conn = ConnectionBuilder::session()?
|
||||
.name("com.system76.CosmicSession")?
|
||||
.serve_at(
|
||||
"/com/system76/CosmicSession",
|
||||
|
|
@ -222,19 +222,22 @@ async fn main() -> Result<()> {
|
|||
loop {
|
||||
tokio::select! {
|
||||
_ = compositor_handle => {
|
||||
info!("compositor exited");
|
||||
info!("EXITING: compositor exited");
|
||||
break;
|
||||
},
|
||||
_ = exit_rx => {
|
||||
info!("session exited by request");
|
||||
res = exit_rx => {
|
||||
if res.is_err() {
|
||||
warn!("exit channel dropped session");
|
||||
}
|
||||
info!("EXITING: session exited by request");
|
||||
break;
|
||||
},
|
||||
signal = signals.next() => match signal {
|
||||
Some(libc::SIGTERM | libc::SIGINT) => {
|
||||
info!("received request to terminate");
|
||||
info!("EXITING: received request to terminate");
|
||||
break;
|
||||
}
|
||||
Some(signal) => unreachable!("received unhandled signal {}", signal),
|
||||
Some(signal) => unreachable!("EXITING: received unhandled signal {}", signal),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,23 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use color_eyre::{eyre::WrapErr, Result};
|
||||
use systemd_client::manager::{SystemdManagerProxy, SystemdManagerProxyBlocking};
|
||||
|
||||
pub async fn start_systemd_target() -> Result<()> {
|
||||
let connection = zbus::Connection::session().await?;
|
||||
let manager = SystemdManagerProxy::new(&connection)
|
||||
.await
|
||||
.wrap_err("failed to connect to org.freedesktop.systemd1.Manager")?;
|
||||
manager
|
||||
.start_unit("cosmic-session.target", "replace")
|
||||
.await
|
||||
.wrap_err("failed to start cosmic-session.target")?;
|
||||
let _ = std::process::Command::new("systemctl")
|
||||
.arg("start")
|
||||
.arg("--user")
|
||||
.arg("cosmic-session.target")
|
||||
.spawn()
|
||||
.wrap_err("Failed to start multi-user.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")?;
|
||||
let _ = std::process::Command::new("systemctl")
|
||||
.arg("stop")
|
||||
.arg("--user")
|
||||
.arg("cosmic-session.target")
|
||||
.spawn()
|
||||
.wrap_err("Failed to stop multi-user.target")?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue