Ignore Ctrl-C and enable Ctrl-D
[ldk-sample] / src / main.rs
index 6cff9f152492058c156e7fb1cf48ccb4e3910f38..f3d888bca37e6818e0e4db727a64792c014fbdf6 100644 (file)
@@ -775,5 +775,28 @@ async fn start_ldk() {
 
 #[tokio::main]
 pub async fn main() {
+       #[cfg(not(target_os = "windows"))]
+       {
+               // Catch Ctrl-C with a dummy signal handler.
+               unsafe {
+                       let mut new_action: libc::sigaction = core::mem::zeroed();
+                       let mut old_action: libc::sigaction = core::mem::zeroed();
+
+                       extern "C" fn dummy_handler(
+                               _: libc::c_int, _: *const libc::siginfo_t, _: *const libc::c_void,
+                       ) {
+                       }
+
+                       new_action.sa_sigaction = dummy_handler as libc::sighandler_t;
+                       new_action.sa_flags = libc::SA_SIGINFO;
+
+                       libc::sigaction(
+                               libc::SIGINT,
+                               &new_action as *const libc::sigaction,
+                               &mut old_action as *mut libc::sigaction,
+                       );
+               }
+       }
+
        start_ldk().await;
 }