daemon: mask SIGHUP

This commit is contained in:
Alex Zenla
2024-03-05 23:10:31 +00:00
parent 0f85e30149
commit f8e2f50c60
3 changed files with 11 additions and 0 deletions

View File

@ -31,6 +31,7 @@ futures = { workspace = true }
bytes = { workspace = true }
tokio-stream = { workspace = true }
async-trait = { workspace = true }
signal-hook = { workspace = true }
[dependencies.tokio-listener]
workspace = true

View File

@ -1,3 +1,5 @@
use std::sync::{atomic::AtomicBool, Arc};
use anyhow::{anyhow, Result};
use clap::Parser;
use env_logger::Env;
@ -15,6 +17,7 @@ struct Args {
#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
async fn main() -> Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init();
mask_sighup()?;
let args = Args::parse();
let Some(listener) = args.listener.bind().await else {
@ -25,3 +28,9 @@ async fn main() -> Result<()> {
daemon.listen(listener?).await?;
Ok(())
}
fn mask_sighup() -> Result<()> {
let flag = Arc::new(AtomicBool::new(false));
signal_hook::flag::register(signal_hook::consts::SIGHUP, flag)?;
Ok(())
}