Skip to content

Commit

Permalink
tokio: add support for signals up to SIGRTMAX (#4555)
Browse files Browse the repository at this point in the history
The POSIX standard not only supports "reliable signals", but also
"real-time signals". This commit adds support for the latter.
  • Loading branch information
weisbrja committed Mar 5, 2022
1 parent 5b947ca commit e8ae65a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tokio/src/signal/registry.rs
Expand Up @@ -237,7 +237,7 @@ mod tests {
#[test]
fn record_invalid_event_does_nothing() {
let registry = Registry::new(vec![EventInfo::default()]);
registry.record_event(42);
registry.record_event(1302);
}

#[test]
Expand Down
14 changes: 9 additions & 5 deletions tokio/src/signal/unix.rs
Expand Up @@ -22,13 +22,17 @@ use self::driver::Handle;

pub(crate) type OsStorage = Vec<SignalInfo>;

// Number of different unix signals
// (FreeBSD has 33)
const SIGNUM: usize = 33;

impl Init for OsStorage {
fn init() -> Self {
(0..SIGNUM).map(|_| SignalInfo::default()).collect()
// There are reliable signals ranging from 1 to 33 available on every Unix platform.
#[cfg(not(target_os = "linux"))]
let possible = 0..=33;

// On Linux, there are additional real-time signals available.
#[cfg(target_os = "linux")]
let possible = 0..=libc::SIGRTMAX();

possible.map(|_| SignalInfo::default()).collect()
}
}

Expand Down

0 comments on commit e8ae65a

Please sign in to comment.