✨ D-Bus session service, currently only used to exit.
This commit is contained in:
parent
d13768607c
commit
2bda93e030
4 changed files with 61 additions and 21 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -5,6 +5,7 @@ extern crate tracing;
|
|||
mod comp;
|
||||
mod generic;
|
||||
mod process;
|
||||
mod service;
|
||||
mod systemd;
|
||||
|
||||
use async_signals::Signals;
|
||||
|
|
@ -14,6 +15,7 @@ use tokio::sync::{mpsc, oneshot};
|
|||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::metadata::LevelFilter;
|
||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||
use zbus::ConnectionBuilder;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> Result<()> {
|
||||
|
|
@ -77,6 +79,15 @@ async fn main() -> Result<()> {
|
|||
);
|
||||
socket_tx.send(sockets).unwrap();
|
||||
|
||||
let (exit_tx, exit_rx) = oneshot::channel();
|
||||
let _ = ConnectionBuilder::session()?
|
||||
.name("com.system76.CosmicSession")?
|
||||
.serve_at("/com/system76/CosmicSession", service::SessionService {
|
||||
exit_tx: Some(exit_tx),
|
||||
})?
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
let mut signals = Signals::new(vec![libc::SIGTERM, libc::SIGINT]).unwrap();
|
||||
loop {
|
||||
tokio::select! {
|
||||
|
|
@ -84,6 +95,10 @@ async fn main() -> Result<()> {
|
|||
info!("compositor exited");
|
||||
break;
|
||||
},
|
||||
_ = exit_rx => {
|
||||
info!("session exited by request");
|
||||
break;
|
||||
},
|
||||
signal = signals.next() => match signal {
|
||||
Some(libc::SIGTERM | libc::SIGINT) => {
|
||||
info!("received request to terminate");
|
||||
|
|
|
|||
21
src/service.rs
Normal file
21
src/service.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
use tokio::sync::oneshot;
|
||||
use zbus::dbus_interface;
|
||||
|
||||
pub struct SessionService {
|
||||
pub exit_tx: Option<oneshot::Sender<()>>,
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "com.system76.CosmicSession")]
|
||||
impl SessionService {
|
||||
async fn exit(&mut self) {
|
||||
match self.exit_tx.take() {
|
||||
Some(tx) => {
|
||||
tx.send(()).ok();
|
||||
}
|
||||
None => {
|
||||
warn!("previously failed to properly exit session");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue