From cdf4297f9f2bd716b75890613be6425bb6a29086 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 19 Mar 2024 18:13:35 -0700 Subject: [PATCH] main: Wait on ctrl-c --- Cargo.toml | 2 +- src/main.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 23646e1..ccb7b20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ strip="symbols" [dependencies] anyhow = "1" -tokio = { version = "1", features = ["fs", "process", "io-std", "rt-multi-thread", "macros"] } +tokio = { version = "1", features = ["fs", "io-std", "macros", "process", "rt-multi-thread", "signal"] } tracing = { version = "0.1", default-features = false } tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] } zbus = { version = "4", features = ["tokio"] } diff --git a/src/main.rs b/src/main.rs index 7f96bbd..95179d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,11 +23,12 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use anyhow::Result; +use anyhow::{Error, Result}; +use tokio::signal::unix::{signal, SignalKind}; use tracing_subscriber; use zbus::ConnectionBuilder; -pub mod manager; +mod manager; #[tokio::main] async fn main() -> Result<()> { @@ -36,6 +37,8 @@ async fn main() -> Result<()> { tracing_subscriber::fmt::init(); + let mut sigterm = signal(SignalKind::terminate())?; + let manager = manager::SMManager::new()?; let _system_connection = ConnectionBuilder::system()? @@ -44,7 +47,8 @@ async fn main() -> Result<()> { .build() .await?; - loop { - std::future::pending::<()>().await; + tokio::select! { + e = sigterm.recv() => e.ok_or(Error::msg("SIGTERM pipe broke")), + e = tokio::signal::ctrl_c() => Ok(e?), } }