Skip to content

Commit b29529c

Browse files
committed
better handling of ctrl-c
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
1 parent b6f8212 commit b29529c

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

fault/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
## Changed
44

5-
- Variety of minor cleanups
5+
- Better handling of Ctrl-C on the inject command

fault/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ members = ["fault-cli", "fault-ebpf-programs"]
44
default-members = ["fault-cli"]
55

66
[workspace.package]
7-
version = "0.11.0"
7+
version = "0.11.1"
88
edition = "2024"
99
rust-version = "1.85"
1010
license-file = "LICENSE"

fault/fault-cli/src/main.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -833,24 +833,33 @@ pub async fn run_fault_injector_roundtrip<P: Platform>(
833833
svc.name.yellow()
834834
);
835835

836-
if let Some(duration) = duration {
837-
match parse_duration::parse(duration.as_str()) {
836+
match duration {
837+
Some(d) => match parse_duration::parse(d.as_str()) {
838838
Ok(total) => {
839-
println!(" Injecting fault for {}", duration);
840-
sleep(total).await
839+
println!(" Injecting fault for {}", d);
840+
tokio::select! {
841+
_ = tokio::signal::ctrl_c() => {
842+
tracing::info!("Shutdown signal received. Initiating shutdown.");
843+
}
844+
845+
_ = sleep(total) => {
846+
tracing::info!("Time's up! Shutting down now.");
847+
}
848+
}
841849
}
842850
Err(_) => anyhow::bail!("failed to parse the duration flag"),
851+
},
852+
None => {
853+
let _ = Confirm::new(&format!(
854+
"Press '{}' to finish and rollback",
855+
"y".to_string().green()
856+
))
857+
.prompt();
843858
}
844-
} else {
845-
let _ = Confirm::new(&format!(
846-
"Press '{}' to finish and rollback",
847-
"y".to_string().green()
848-
))
849-
.prompt();
850859
}
851860

852-
plt.rollback().await?;
853861
println!(" Rolling back fault...");
862+
plt.rollback().await?;
854863
//plt.wait_cleanup().await?;
855864
println!(" Rolled back.");
856865

0 commit comments

Comments
 (0)