diff --git a/Cargo.lock b/Cargo.lock index c2be144..7ce64a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1525,8 +1525,6 @@ dependencies = [ "pin-utils", "serde", "serde_json", - "signal-hook", - "signal-hook-tokio", "streamstore", "thiserror", "tokio", @@ -1618,16 +1616,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -1637,18 +1625,6 @@ dependencies = [ "libc", ] -[[package]] -name = "signal-hook-tokio" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213241f76fb1e37e27de3b6aa1b068a2c333233b59cca6634f634b80a27ecf1e" -dependencies = [ - "futures-core", - "libc", - "signal-hook", - "tokio", -] - [[package]] name = "slab" version = "0.4.9" diff --git a/Cargo.toml b/Cargo.toml index a80473c..758763b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,6 @@ pin-project-lite = "0.2" pin-utils = "0.1.0" serde = { version = "1.0.214", features = ["derive"] } serde_json = "1.0.132" -signal-hook = "0.3.17" -signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] } thiserror = "1.0.67" tokio = { version = "1.41.1", features = ["full"] } tokio-stream = { version = "0.1.16", features = ["io-util"] } diff --git a/src/main.rs b/src/main.rs index bb75f4a..1f43432 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,8 +9,6 @@ use clap::{builder::styling, Parser, Subcommand}; use colored::*; use config::{config_path, create_config}; use error::{S2CliError, ServiceError, ServiceErrorContext}; -use signal_hook::consts::{SIGINT, SIGTERM, SIGTSTP}; -use signal_hook_tokio::Signals; use stream::{RecordStream, StreamService}; use streamstore::{ client::{BasinClient, Client, ClientConfig, S2Endpoints, StreamClient}, @@ -20,6 +18,7 @@ use streamstore::{ }, HeaderValue, }; +use tokio::signal; use tokio::{ fs::{File, OpenOptions}, io::{self, AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, BufReader, BufWriter}, @@ -573,9 +572,6 @@ async fn run() -> Result<(), S2CliError> { .lines(), ); - let mut signals = - Signals::new([SIGTSTP, SIGINT, SIGTERM]).expect("valid signals"); - let mut append_output_stream = StreamService::new(stream_client) .append_session(append_input_stream, fencing_token, match_seq_num) .await?; @@ -607,16 +603,11 @@ async fn run() -> Result<(), S2CliError> { } } - Some(signal) = signals.next() => { - match signal { - SIGTSTP | SIGINT | SIGTERM => { - drop(append_output_stream); - eprintln!("{}", "■ [ABORTED]".red().bold()); - break; - } - _ => {} + _ = signal::ctrl_c() => { + drop(append_output_stream); + eprintln!("{}", "■ [ABORTED]".red().bold()); + break; } - } } } } @@ -627,8 +618,6 @@ async fn run() -> Result<(), S2CliError> { limit_bytes, } => { let stream_client = StreamClient::new(client_config, basin, stream); - let mut signals = - Signals::new([SIGTSTP, SIGINT, SIGTERM]).expect("valid signals"); let mut read_output_stream = StreamService::new(stream_client) .read_session(start_seq_num, limit_count, limit_bytes) .await?; @@ -704,15 +693,10 @@ async fn run() -> Result<(), S2CliError> { None => break, } }, - Some(signal) = signals.next() => { - match signal { - SIGTSTP | SIGINT | SIGTERM => { - drop(read_output_stream); - eprintln!("{}", "■ [ABORTED]".red().bold()); - break; - } - _ => {} - } + _ = signal::ctrl_c() => { + drop(read_output_stream); + eprintln!("{}", "■ [ABORTED]".red().bold()); + break; } } let total_elapsed_time = start.unwrap().elapsed().as_secs_f64();