Skip to content

Commit

Permalink
Handle signal error on re-registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
qnighy committed Jul 25, 2019
1 parent 07afa5c commit 5012717
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions signal-hook-registry/src/lib.rs
Expand Up @@ -228,8 +228,17 @@ extern "C" fn handler(sig: c_int) {
// Problems:
// - It's racy. But this is inevitably racy in Windows.
// - Interacts poorly with handlers outside signal-hook-registry.
unsafe {
libc::signal(sig, handler as sighandler_t);
let old = unsafe { libc::signal(sig, handler as sighandler_t) };
if old == SIG_ERR {
// MSDN doesn't describe which errors might occur,
// but we can tell from the Linux manpage that
// EINVAL (invalid signal number) is mostly the only case.
// Therefore, this branch must not occur.
// In any case we can do nothing useful in the signal handler,
// so we're going to abort silently.
unsafe {
libc::abort();
}
}
}

Expand Down

0 comments on commit 5012717

Please sign in to comment.