From a4ca29ad389f451d50f03d830495a286cbd23006 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Mon, 13 Sep 2021 16:51:55 +1000 Subject: [PATCH] linkd: Developers, Developers, Dev... Signed-off-by: Alexander Simmerl --- node-lib/src/lib.rs | 2 ++ node-lib/src/node.rs | 25 +++++++++++-------------- node-lib/src/signals.rs | 15 +++++++-------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/node-lib/src/lib.rs b/node-lib/src/lib.rs index ab543ec9c..bbea36b9b 100644 --- a/node-lib/src/lib.rs +++ b/node-lib/src/lib.rs @@ -13,4 +13,6 @@ mod metrics; pub mod node; mod protocol; mod signals; + +#[cfg(unix)] pub mod socket_activation; diff --git a/node-lib/src/node.rs b/node-lib/src/node.rs index a9908588e..34e6255d1 100644 --- a/node-lib/src/node.rs +++ b/node-lib/src/node.rs @@ -7,7 +7,7 @@ use std::panic; use futures::future::{select_all, FutureExt as _}; use structopt::StructOpt as _; -use tokio::{net::UnixStream, spawn, sync::mpsc}; +use tokio::{spawn, sync::mpsc}; use tracing::info; use librad::{ @@ -22,7 +22,6 @@ use crate::{ metrics::graphite, protocol, signals, - socket_activation, }; pub async fn run() -> anyhow::Result<()> { @@ -44,13 +43,13 @@ pub async fn run() -> anyhow::Result<()> { coalesced.push(graphite_task); } - if let Some(_listener) = socket_activation::env()? { - // TODO(xla): Schedule listen loop. - } else { - // TODO(xla): Bind to configured/default socket path, constructed from - // profile info. - // TODO(xla): Schedule listen loop. - } + // if let Some(_listener) = socket_activation::env()? { + // TODO(xla): Schedule listen loop. + // } else { + // TODO(xla): Bind to configured/default socket path, constructed from + // profile info. + // TODO(xla): Schedule listen loop. + // } // TODO(xla): Setup subroutines. // - Public API @@ -74,12 +73,10 @@ pub async fn run() -> anyhow::Result<()> { #[cfg(unix)] async fn cfg(args: &Args) -> anyhow::Result> { - Ok(Cfg::from_args::(args).await?) + Ok(Cfg::from_args::(args).await?) } -#[cfg(not(unix))] +#[cfg(windows)] async fn cfg(args: &Args) -> anyhow::Result> { - use tokio::net::TcpSocket; - - Ok(Cfg::from_args::(args).await?) + Ok(Cfg::from_args::(args).await?) } diff --git a/node-lib/src/signals.rs b/node-lib/src/signals.rs index 008ecab40..8b2e16b43 100644 --- a/node-lib/src/signals.rs +++ b/node-lib/src/signals.rs @@ -16,7 +16,7 @@ pub async fn routine(shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> { let mut term = signal(SignalKind::terminate())?; let signal = select! { - _ = int.recv() => SignalKind::quit(), + _ = int.recv() => SignalKind::interrupt(), _ = quit.recv() => SignalKind::quit(), _ = term.recv() => SignalKind::terminate(), }; @@ -27,20 +27,19 @@ pub async fn routine(shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> { Ok(()) } -#[cfg(target_os = "windows")] -#[instrument(name = "signals subroutine", skip(signals, shutdown_tx))] -pub async fn routine(signals: Signals, shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> { +#[cfg(windows)] +#[instrument(name = "signals subroutine", skip(shutdown_tx))] +pub async fn routine(shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> { use tokio::signal::windows::*; let mut br = ctrl_break()?; - let mut c = cltr_c()?; + let mut c = ctrl_c()?; let signal = select! { - _ = br.recv() => SignalKind::quit(), - _ = c.recv() => SignalKind::quit(), + _ = br.recv() => info!("received Break signal"), + _ = c.recv() => info!("recieved CtrlC signal"), }; - info!(?signal, "received termination signal"); let _ = shutdown_tx.try_send(()); Ok(())