diff --git a/bffhd/lib.rs b/bffhd/lib.rs index f6607f0..398c8e5 100644 --- a/bffhd/lib.rs +++ b/bffhd/lib.rs @@ -43,6 +43,7 @@ use std::path::Path; use std::sync::Arc; use anyhow::Context; use futures_rustls::TlsAcceptor; +use futures_util::StreamExt; use rustls::{Certificate, KeyLogFile, PrivateKey, ServerConfig}; use rustls::server::NoClientAuth; use signal_hook::consts::signal::*; @@ -75,18 +76,32 @@ impl Diflouroborane { self.log_version_number(); - let signals = signal_hook_async_std::Signals::new(&[ + let mut signals = signal_hook_async_std::Signals::new(&[ SIGINT, SIGQUIT, SIGTERM, ]).context("Failed to construct signal handler")?; - tracing::debug!("Set up signal handler"); let tlsconfig = TlsConfig::new(config.tlskeylog.as_ref(), !config.is_quiet())?; let acceptor = tlsconfig.make_tls_acceptor(&config.tlsconfig)?; - APIServer::bind(self.executor.clone(), &config.listens, acceptor); + let mut apiserver = self.executor.run(APIServer::bind(self.executor.clone(), &config.listens, acceptor))?; + let (mut tx, rx) = async_oneshot::oneshot(); + + self.executor.spawn(apiserver.handle_until(rx)); + + let f = async { + let mut sig = None; + while { + sig = signals.next().await; + sig.is_none() + } {} + tracing::info!(signal = %sig.unwrap(), "Received signal"); + tx.send(()); + }; + + self.executor.run(f); Ok(()) } } \ No newline at end of file diff --git a/bin/bffhd/main.rs b/bin/bffhd/main.rs index 17cba6b..6646bc2 100644 --- a/bin/bffhd/main.rs +++ b/bin/bffhd/main.rs @@ -131,7 +131,7 @@ fn main() -> anyhow::Result<()> { config.log_format = matches.value_of("log format").unwrap_or("Full").to_string(); let mut bffh = Diflouroborane::new(); - bffh.setup(&config); + bffh.setup(&config)?; } Ok(())