From 77ec6d4e7ea237552786849c1f345fc77719321e Mon Sep 17 00:00:00 2001 From: "weisbrja@thinkpad" Date: Thu, 3 Mar 2022 04:59:41 +0100 Subject: [PATCH 1/4] tokio: add support for signals up to SIGRTMAX The POSIX standard not only supports "reliable signals", but also "real-time signals". This commit adds support for the latter. Fixes: #4554 --- tokio/src/signal/registry.rs | 2 +- tokio/src/signal/unix.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tokio/src/signal/registry.rs b/tokio/src/signal/registry.rs index 6d8eb9e7487..7795ca8dfa8 100644 --- a/tokio/src/signal/registry.rs +++ b/tokio/src/signal/registry.rs @@ -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] diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs index b84cbb71805..285c2dee0a6 100644 --- a/tokio/src/signal/unix.rs +++ b/tokio/src/signal/unix.rs @@ -22,13 +22,11 @@ use self::driver::Handle; pub(crate) type OsStorage = Vec; -// 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() + (0..libc::SIGRTMAX()) + .map(|_| SignalInfo::default()) + .collect() } } From e3d1489cda6533450a8bc01d6a93a3aeb830ff9a Mon Sep 17 00:00:00 2001 From: "weisbrja@thinkpad" Date: Thu, 3 Mar 2022 05:17:28 +0100 Subject: [PATCH 2/4] tokio: made signals up to SIGRTMAX available only on Linux --- tokio/src/signal/unix.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs index 285c2dee0a6..16aaad53825 100644 --- a/tokio/src/signal/unix.rs +++ b/tokio/src/signal/unix.rs @@ -24,7 +24,15 @@ pub(crate) type OsStorage = Vec; impl Init for OsStorage { fn init() -> Self { - (0..libc::SIGRTMAX()) + // There are at least 33 reliable signals 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() } From 75dc6e123ac9e3f062fb5eea7484517f30dfbb55 Mon Sep 17 00:00:00 2001 From: "weisbrja@thinkpad" Date: Fri, 4 Mar 2022 17:43:53 +0100 Subject: [PATCH 3/4] tokio: included signal 33 and SIGRTMAX --- tokio/src/signal/unix.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs index 16aaad53825..f2d5043ffa9 100644 --- a/tokio/src/signal/unix.rs +++ b/tokio/src/signal/unix.rs @@ -24,13 +24,13 @@ pub(crate) type OsStorage = Vec; impl Init for OsStorage { fn init() -> Self { - // There are at least 33 reliable signals available on every Unix platform. + // There are reliable signals ranging from 1 to 33 available on every Unix platform. #[cfg(not(target_os = "linux"))] - let possible = 0..33; + let possible = 0..=33; // On Linux, there are additional real-time signals available. #[cfg(target_os = "linux")] - let possible = 0..libc::SIGRTMAX(); + let possible = 0..=libc::SIGRTMAX(); possible .map(|_| SignalInfo::default()) From 879534605425c6cec2bd5dd463cad1662dabd391 Mon Sep 17 00:00:00 2001 From: "weisbrja@thinkpad" Date: Fri, 4 Mar 2022 21:56:56 +0100 Subject: [PATCH 4/4] tokio: fixed formatting --- tokio/src/signal/unix.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs index f2d5043ffa9..139d7834f2c 100644 --- a/tokio/src/signal/unix.rs +++ b/tokio/src/signal/unix.rs @@ -32,9 +32,7 @@ impl Init for OsStorage { #[cfg(target_os = "linux")] let possible = 0..=libc::SIGRTMAX(); - possible - .map(|_| SignalInfo::default()) - .collect() + possible.map(|_| SignalInfo::default()).collect() } }