Skip to content

Commit 480c010

Browse files
authored
signal: add SignalKind::info on illumos (#6995)
1 parent c032ea0 commit 480c010

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

tokio/src/signal/unix.rs

+15-2
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 this capability isn't exposed
38+
// by libc as of 0.2.167, so we don't support them at the moment. Once
39+
// https://github.com/rust-lang/libc/pull/4171 is merged and released in
40+
// upstream libc, we should switch the illumos impl to do what Linux
41+
// does.
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

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
use tokio::time::{timeout, Duration};
22+
23+
#[tokio::test]
24+
async fn siginfo() {
25+
let mut sig = signal::unix::signal(SignalKind::info()).expect("installed signal handler");
26+
27+
let (fire, wait) = oneshot::channel();
28+
29+
// NB: simulate a signal coming in by exercising our signal handler
30+
// to avoid complications with sending SIGINFO to the test process
31+
tokio::spawn(async {
32+
wait.await.expect("wait failed");
33+
send_signal(libc::SIGINFO);
34+
});
35+
36+
let _ = fire.send(());
37+
38+
// Add a timeout to ensure the test doesn't hang.
39+
timeout(Duration::from_secs(5), sig.recv())
40+
.await
41+
.expect("received SIGINFO signal in time")
42+
.expect("received SIGINFO signal");
43+
}

0 commit comments

Comments
 (0)