diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db8c609..6f6412c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,7 +104,7 @@ jobs: run: cargo minimal-versions test -- --test-threads 1 min-versions-msrv: - name: Minimal Depencency Versions (MSRV) + name: Minimal Dependency Versions (MSRV) runs-on: ubuntu-latest needs: [lints, docs] env: diff --git a/src/signal_handling.rs b/src/signal_handling.rs index 5a1b5c6..7695c00 100644 --- a/src/signal_handling.rs +++ b/src/signal_handling.rs @@ -3,6 +3,8 @@ async fn wait_for_signal_impl() { use tokio::signal::unix::{signal, SignalKind}; + // Infos here: + // https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html let mut signal_terminate = signal(SignalKind::terminate()).unwrap(); let mut signal_interrupt = signal(SignalKind::interrupt()).unwrap(); @@ -15,15 +17,25 @@ async fn wait_for_signal_impl() { /// Waits for a signal that requests a graceful shutdown, Ctrl-C (SIGINT). #[cfg(windows)] async fn wait_for_signal_impl() { - use tokio::signal::ctrl_c; + use tokio::signal::windows; - ctrl_c().await.unwrap(); - tracing::debug!("Received SIGINT."); + // Infos here: + // https://learn.microsoft.com/en-us/windows/console/handlerroutine + let mut signal_c = windows::ctrl_c().unwrap(); + let mut signal_break = windows::ctrl_break().unwrap(); + let mut signal_close = windows::ctrl_close().unwrap(); + let mut signal_shutdown = windows::ctrl_shutdown().unwrap(); + + tokio::select! { + _ = signal_c.recv() => tracing::debug!("Received CTRL_C."), + _ = signal_break.recv() => tracing::debug!("Received CTRL_BREAK."), + _ = signal_close.recv() => tracing::debug!("Received CTRL_CLOSE."), + _ = signal_shutdown.recv() => tracing::debug!("Received CTRL_SHUTDOWN."), + }; } -/// Registers Ctrl+C and SIGTERM handlers to cause a program shutdown. -/// Further, registers a custom panic handler to also initiate a shutdown. -/// Otherwise, a multi-threaded system would deadlock on panik. +/// Registers signal handlers and waits for a signal that +/// indicates a shutdown request. pub(crate) async fn wait_for_signal() { wait_for_signal_impl().await } diff --git a/src/toplevel.rs b/src/toplevel.rs index 3476ae7..91fbd73 100644 --- a/src/toplevel.rs +++ b/src/toplevel.rs @@ -102,10 +102,14 @@ impl Toplevel { /// The following signals will be handled: /// /// - On Windows: - /// - Ctrl+C (SIGINT) + /// - `CTRL_C` + /// - `CTRL_BREAK` + /// - `CTRL_CLOSE` + /// - `CTRL_SHUTDOWN` /// /// - On Unix: - /// - SIGINT and SIGTERM + /// - `SIGINT` + /// - `SIGTERM` /// /// # Caveats ///