Merge pull request #77 from tnull/2022-10-catch-ctrlc
[ldk-sample] / src / main.rs
index 9ecc5e39a9f1444332601d29d662b46048cc5add..0d5915d9effc49415a10e0080a49e90af83aae81 100644 (file)
@@ -772,5 +772,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;
 }