KeyBoxen 0.1.0

Standalone secret-service daemon for window managers
// Copyright (C) 2022 KeyBoxen Authors
// SPDX-License-Identifier: GPL-3.0-or-later

mod database;
mod pinentry;
mod service;

use signal_hook::consts::signal::*;
use signal_hook_tokio::Signals;
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() -> zbus::Result<()> {
    let root = service::Service::empty();

    zbus::ConnectionBuilder::session()?
        // The bus name should have 'secrets' in lowercase. This is a
        // temporary measure considering the presence of other secret
        // servers. Change it to lower case when keyboxen is ready to
        // be the one secret server.
        .name("org.freedesktop.Secrets")?
        .serve_at("/org/freedesktop/secrets", root)?
        .build()
        .await?;

    println!("KeyBoxen is now serving secrets!");

    // Wait on SIGINT and SIGTERM to exit the process
    let mut signals = Signals::new(&[SIGTERM, SIGINT])?;
    if let Some(sig) = signals.next().await {
        let sig = match sig {
            SIGTERM => "SIGTERM",
            SIGINT => "SIGINT",
            _ => unreachable!(),
        }
        .to_string();
        println!("Exiting normally on {}.", sig);
    }

    // Exit with status OK
    zbus::Result::Ok(())
}