From 35ab20ab0d1fe4ba2dd86ae21036819a909c5833 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 15 Jan 2026 15:09:27 +0900 Subject: [PATCH] Handle SIGTERM along SIGINT. This means a plain 'pkill mitm-cache' will also cause the out.json file to be written before terminating. * src/main.rs: Add a handler for SIGTERM. Fixes: #2 --- src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index d9f760f..d1fb7e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,9 +30,15 @@ use std::{ use tokio::{io::AsyncReadExt, sync::RwLock}; async fn shutdown_signal() { - tokio::signal::ctrl_c() - .await - .expect("Failed to install CTRL+C signal handler"); + let mut sigterm = tokio::signal::unix::signal( + tokio::signal::unix::SignalKind::terminate()) + .expect("Failed to install SIGTERM signal handler"); + + // Shutdown on either SIGINT or SIGTERM. + tokio::select! { + _ = tokio::signal::ctrl_c() => {}, + _ = sigterm.recv() => {}, + } } #[derive(Clone, Debug, Serialize)]