mirror of
https://github.com/cirruslabs/softnet.git
synced 2026-09-29 19:41:10 +02:00
Support graceful termination via SIGINT (#23)
* Support graceful termination via SIGINT * $ cargo fmt * Explain why we need to ignore the SIGINT
This commit is contained in:
+10
-1
@@ -1,5 +1,6 @@
|
||||
use anyhow::{anyhow, Context};
|
||||
use clap::Parser;
|
||||
use nix::sys::signal::{signal, SigHandler, Signal};
|
||||
use privdrop::PrivDrop;
|
||||
use softnet::proxy::Proxy;
|
||||
use std::borrow::Cow;
|
||||
@@ -55,7 +56,7 @@ fn main() -> ExitCode {
|
||||
|
||||
// Initialize Sentry
|
||||
let _sentry = sentry::init(sentry::ClientOptions {
|
||||
release: option_env!("CIRRUS_TAG").map(|tag| { Cow::from(format!("softnet@{tag}")) }),
|
||||
release: option_env!("CIRRUS_TAG").map(|tag| Cow::from(format!("softnet@{tag}"))),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
@@ -84,6 +85,14 @@ fn main() -> ExitCode {
|
||||
}
|
||||
|
||||
fn try_main() -> anyhow::Result<()> {
|
||||
// The default signal(3)[1] action for SIGINT is to interrupt program,
|
||||
// but we want to handle SIGINT ourselves, so we ignore it. The kqueue(2)'s[2]
|
||||
// EVFILT_SIGNAL will receive it anyways, because it has lower precedence.
|
||||
//
|
||||
// [1]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/signal.3.html
|
||||
// [2]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html
|
||||
unsafe { signal(Signal::SIGINT, SigHandler::SigIgn) }?;
|
||||
|
||||
let args: Args = Args::parse();
|
||||
|
||||
// No need to run anything, just return
|
||||
|
||||
Reference in New Issue
Block a user