Skip to content

Commit ced8d59

Browse files
committed
style(cli): remove synchronous signal handling code that used unsafe blocks
1 parent 3c6fabd commit ced8d59

1 file changed

Lines changed: 6 additions & 48 deletions

File tree

crates/cli/src/setup.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,13 @@ pub fn is_shutdown_requested() -> bool {
2222

2323
/// Install signal handlers for graceful shutdown.
2424
///
25-
/// - First Ctrl+C (SIGINT): sets the shutdown flag so the agent loop can
26-
/// exit gracefully.
27-
/// - Second Ctrl+C: force-exits with code 130 (standard SIGINT exit code).
28-
/// - On Unix, SIGTERM triggers an immediate graceful shutdown.
25+
/// Signal delivery is handled by [`spawn_async_signal_handlers`] once the
26+
/// Tokio runtime is running. There is no synchronous pre-runtime handler here
27+
/// because the build forbids `unsafe` code.
2928
pub fn install_signal_handlers() {
30-
// Use tokio's ctrl_c / signal support is async-only.
31-
// For synchronous setup we use std::process + ctrlc-style handler
32-
// via the tokio::signal API at runtime. Here we install a simple
33-
// atomic flag approach using Rust's built-in set_handler.
34-
//
35-
// Note: std::panic::set_hook is separate; this only handles OS signals.
36-
37-
// On all platforms, handle Ctrl+C via a closure that checks SIGINT count.
38-
let _ = ctrlc_handler();
39-
}
40-
41-
/// Register a Ctrl+C handler using platform-appropriate mechanisms.
42-
fn ctrlc_handler() {
43-
// We cannot use tokio::signal here because we need a sync handler
44-
// that works before the runtime is up. Instead, spawn a background
45-
// thread that blocks on tokio::signal::ctrl_c once the runtime starts.
46-
//
47-
// For the sync path: use std's set_handler (unsafe but standard).
48-
#[cfg(unix)]
49-
{
50-
// On Unix, also listen for SIGTERM
51-
unsafe {
52-
libc_signal_handler();
53-
}
54-
}
55-
56-
// Cross-platform Ctrl+C via std (works on Windows too)
57-
#[cfg(not(unix))]
58-
{
59-
// On Windows, we rely on the tokio signal handler installed later.
60-
// Set a basic handler here for pre-runtime coverage.
61-
let _ = std::panic::catch_unwind(|| {
62-
// No-op: Windows Ctrl+C is handled by the async runtime.
63-
});
64-
}
65-
}
66-
67-
#[cfg(unix)]
68-
unsafe fn libc_signal_handler() {
69-
// Best-effort: if this fails, the async handler will still work.
70-
let _ = std::panic::catch_unwind(|| {
71-
// SIGINT and SIGTERM are handled by tokio signal in async context.
72-
// This function is a placeholder for future low-level signal work.
73-
});
29+
// The CLI relies on the async signal listeners installed after runtime
30+
// startup. Keeping this function lets initialization stay symmetric even
31+
// when no synchronous handler is registered.
7432
}
7533

7634
/// Spawn the async signal listener tasks. Call this after the tokio runtime starts.

0 commit comments

Comments
 (0)