Search code examples
rustsignalsrust-tokio

Why can't tokio listen for signals between SIGRTMIN and SIGRTMAX?


I'm trying to listen to signals between libc::SIGRTMIN() and libc::SIGRTMAX() with tokio, but it fails with "signal too large". However, I was able to listen to these signals with the signal-hook crate.

I tracked the error down with gdb, and the reason it fails, is because of this check in tokio/src/signal/unix.rs:

fn signal_enable(signal: SignalKind, handle: &Handle) -> io::Result<()> {
    // ...

    let globals = globals();
    let siginfo = match globals.storage().get(signal as EventId) {
        Some(slot) => slot,
        None => return Err(io::Error::new(io::ErrorKind::Other, "signal too large")),
    };

    // ...
}

Why is this check there, and why don't the globals contain the signals between SIGRTMIN and SIGRTMAX?

Also, what do I do now that it doesn't work?

Here's the code to reproduce the error:

use tokio::signal::unix::{signal, SignalKind};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let signal = signal(SignalKind::from_raw(libc::SIGRTMIN()))?;
    Ok(())
}

Solution

  • The pull request I opened got accepted and fixed all my problems.