Skip to content

Commit aad2ec1

Browse files
committed
Remove exit(0) from signal handler, use event loop proxy instead
1 parent 9817d58 commit aad2ec1

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

crates/hidpp-daemon/src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ fn run_tray_app(
136136
}
137137

138138
let proxy = event_loop.create_proxy();
139+
let signal_proxy = event_loop.create_proxy();
139140

140141
// Command channel: tray UI → background daemon.
141142
let (cmd_tx, cmd_rx) = tokio::sync::mpsc::channel::<DaemonCommand>(8);
@@ -168,7 +169,7 @@ fn run_tray_app(
168169
}
169170

170171
// Catch SIGTERM (sent by launchd on service stop / system shutdown)
171-
// and trigger a graceful shutdown through the daemon command channel.
172+
// and trigger a graceful shutdown through both the daemon and the event loop.
172173
{
173174
let sigterm_tx = cmd_tx.clone();
174175
std::thread::Builder::new()
@@ -191,10 +192,10 @@ fn run_tray_app(
191192
tokio::signal::ctrl_c().await.ok();
192193
}
193194
info!("received shutdown signal");
194-
if sigterm_tx.send(DaemonCommand::Shutdown).await.is_err() {
195-
// Daemon already exited — nothing to shut down.
196-
std::process::exit(0);
197-
}
195+
// Tell the daemon to clean up HID resources.
196+
let _ = sigterm_tx.send(DaemonCommand::Shutdown).await;
197+
// Tell the event loop to exit (works even if daemon already exited).
198+
let _ = signal_proxy.send_event(DaemonEvent::Shutdown);
198199
});
199200
})
200201
.expect("signal handler thread");

0 commit comments

Comments
 (0)