D-Bus session service, currently only used to exit.

This commit is contained in:
Lucy 2022-07-22 11:48:03 -04:00
parent d13768607c
commit 2bda93e030
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
4 changed files with 61 additions and 21 deletions

38
Cargo.lock generated
View file

@ -174,9 +174,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
version = "1.1.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e"
[[package]]
name = "cache-padded"
@ -240,7 +240,7 @@ dependencies = [
"color-eyre",
"futures-util",
"libc",
"nix 0.24.1",
"nix 0.24.2",
"scopeguard",
"sendfd",
"serde",
@ -415,9 +415,9 @@ dependencies = [
[[package]]
name = "gimli"
version = "0.26.1"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
[[package]]
name = "hermit-abi"
@ -546,9 +546,9 @@ dependencies = [
[[package]]
name = "nix"
version = "0.24.1"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9"
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
dependencies = [
"bitflags",
"cfg-if",
@ -824,18 +824,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.139"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6"
checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.139"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb"
checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da"
dependencies = [
"proc-macro2",
"quote",
@ -899,9 +899,12 @@ dependencies = [
[[package]]
name = "slab"
version = "0.4.6"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32"
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
dependencies = [
"autocfg",
]
[[package]]
name = "smallvec"
@ -1112,9 +1115,9 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
version = "0.3.14"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a713421342a5a666b7577783721d3117f1b69a393df803ee17bb73b1e122a59"
checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b"
dependencies = [
"ansi_term",
"matchers",
@ -1140,9 +1143,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7"
[[package]]
name = "valuable"
@ -1268,6 +1271,7 @@ dependencies = [
"serde_repr",
"sha1",
"static_assertions",
"tokio",
"tracing",
"uds_windows",
"winapi",

View file

@ -13,14 +13,14 @@ color-eyre = "0.6"
futures-util = "0.3"
libc = "0.2"
nix = { version = "0.24", features = ["fs"], default-features = false }
scopeguard = "1.1.0"
scopeguard = "1"
sendfd = { version = "0.4", features = ["tokio"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
systemd_client = "0.2.1"
systemd_client = "0.2"
tokio = { version = "1", features = ["full"] }
tokio-util = "0.7"
tracing = "0.1"
tracing-journald = "0.3.0"
tracing-journald = "0.3"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
zbus = { version = "2.0.1" }
zbus = { version = "2", default-features = false, features = ["tokio"] }

View file

@ -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
View 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");
}
}
}
}