main: Wait on ctrl-c

This commit is contained in:
Vicki Pfau 2024-03-19 18:13:35 -07:00
parent 7e262a1d96
commit cdf4297f9f
2 changed files with 9 additions and 5 deletions

View file

@ -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"] }

View file

@ -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?),
}
}