Skip to content

Commit c69052a

Browse files
committed
signal: add SignalKind::info on illumos
illumos has supported SIGINFO for a long time; see illumos/illumos-gate@19d32b9.
1 parent c07257f commit c69052a

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

tokio/src/signal/unix.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,25 @@ pub(crate) type OsStorage = Box<[SignalInfo]>;
2323
impl Init for OsStorage {
2424
fn init() -> Self {
2525
// There are reliable signals ranging from 1 to 33 available on every Unix platform.
26-
#[cfg(not(target_os = "linux"))]
26+
#[cfg(not(any(target_os = "linux", target_os = "illumos")))]
2727
let possible = 0..=33;
2828

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

33+
// On illumos, signal numbers go up to 41 (SIGINFO). The list of signals
34+
// hasn't changed since 2013. See
35+
// https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/sys/iso/signal_iso.h.
36+
//
37+
// illumos also has real-time signals, but (a) the number of real-time
38+
// signals is actually configurable at runtime and (b) this capability
39+
// isn't exposed by libc as of 0.2.167, so we don't support them at the
40+
// moment. If support for real-time signals on illumos is desired, this
41+
// code would have to be changed to accommodate that.
42+
#[cfg(target_os = "illumos")]
43+
let possible = 0..=41;
44+
3345
possible.map(|_| SignalInfo::default()).collect()
3446
}
3547
}
@@ -130,7 +142,8 @@ impl SignalKind {
130142
target_os = "freebsd",
131143
target_os = "macos",
132144
target_os = "netbsd",
133-
target_os = "openbsd"
145+
target_os = "openbsd",
146+
target_os = "illumos"
134147
))]
135148
pub const fn info() -> Self {
136149
Self(libc::SIGINFO)

tokio/tests/signal_info.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![warn(rust_2018_idioms)]
2+
#![cfg(feature = "full")]
3+
#![cfg(any(
4+
target_os = "dragonfly",
5+
target_os = "freebsd",
6+
target_os = "macos",
7+
target_os = "netbsd",
8+
target_os = "openbsd",
9+
target_os = "illumos"
10+
))]
11+
#![cfg(not(miri))] // No `sigaction` on Miri
12+
13+
mod support {
14+
pub mod signal;
15+
}
16+
use support::signal::send_signal;
17+
18+
use tokio::signal;
19+
use tokio::signal::unix::SignalKind;
20+
use tokio::sync::oneshot;
21+
22+
#[tokio::test]
23+
async fn siginfo() {
24+
let mut sig = signal::unix::signal(SignalKind::info()).expect("installed signal handler");
25+
26+
let (fire, wait) = oneshot::channel();
27+
28+
// NB: simulate a signal coming in by exercising our signal handler
29+
// to avoid complications with sending SIGINFO to the test process
30+
tokio::spawn(async {
31+
wait.await.expect("wait failed");
32+
send_signal(libc::SIGINFO);
33+
});
34+
35+
let _ = fire.send(());
36+
37+
sig.recv().await.expect("received SIGINFO signal");
38+
}

0 commit comments

Comments
 (0)