3

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(())
}
weisbrja
  • 164
  • 10
  • [This link](https://rust-cli.github.io/book/in-depth/signals.html#using-futures-and-streams) mentions that `tokio` and `signal-hook` can be used together, which seems to not be true anymore since version 2 of `signal-hook`. – weisbrja Mar 02 '22 at 22:38
  • tokio signal doesn't handle `SIGRTMIN` and `SIGRTMAX` you could ask such feature I guess – Stargateur Mar 02 '22 at 22:50
  • *"On POSIX-compliant platforms, `SIGRTMIN` through `SIGRTMAX` are signals sent to computer programs for user-defined purposes."* Why doesn't tokio support them? – weisbrja Mar 02 '22 at 22:55
  • Is there an issue on tokio? Better submit there. – battlmonstr Mar 02 '22 at 23:13
  • I'll create a bug report on github. – weisbrja Mar 02 '22 at 23:14
  • [Here](https://github.com/tokio-rs/tokio/issues/4554) is the issue I created. I also created a [pull request](https://github.com/tokio-rs/tokio/pull/4555) that is yet to be reviewed. – weisbrja Mar 03 '22 at 12:20

1 Answers1

1

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

weisbrja
  • 164
  • 10