Skip to content

Commit

Permalink
Make server example signal handling work on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfeldman committed Jun 29, 2023
1 parent d730087 commit 69b5375
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/webserver/platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ unsafe extern "C" fn signal_handler(sig: c_int, _: *mut siginfo_t, _: *mut libc:
});
}

#[cfg(target_os = "macos")]
fn setup_signal(sig: c_int) {
let sa = libc::sigaction {
sa_sigaction: signal_handler as sighandler_t,
Expand All @@ -58,6 +59,28 @@ fn setup_signal(sig: c_int) {
}
}

#[cfg(target_os = "linux")]
fn setup_signal(sig: c_int) {
let sa = libc::sigaction {
sa_sigaction: signal_handler as sighandler_t,
sa_mask: unsafe { std::mem::zeroed() },
sa_flags: SA_SIGINFO,
sa_restorer: None,
};

let mut old_sa = libc::sigaction {
sa_sigaction: SIG_DFL,
sa_mask: unsafe { std::mem::zeroed() },
sa_flags: 0,
sa_restorer: None,
};

unsafe {
sigemptyset(&mut old_sa.sa_mask as *mut sigset_t);
sigaction(sig, &sa, &mut old_sa);
}
}

fn call_roc(req_bytes: &[u8]) -> Response<Body> {
let mut setjmp_result = 0;

Expand Down

0 comments on commit 69b5375

Please sign in to comment.