Skip to content

Commit 197e35f

Browse files
committed
Make SignalSet::termination work for all targets
Conditionally enables signals if they're available. This would make for an amazing use case of `#[cfg(accessible(...))]`. See rust-lang/rust#64797 for info on this.
1 parent 059066a commit 197e35f

File tree

1 file changed

+67
-10
lines changed

1 file changed

+67
-10
lines changed

src/unix/signal_set.rs

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,76 @@ impl SignalSet {
7777

7878
/// Creates a new set of signals that result in process termination.
7979
///
80-
/// The included signals are only those that can be gracefully handled.
80+
/// This only includes signals that can be trivially handled with grace:
81+
/// - [`alarm`](#method.alarm)
82+
/// - [`hangup`](#method.hangup)
83+
/// - [`interrupt`](#method.interrupt)
84+
/// - [`pipe`](#method.pipe)
85+
/// - [`quit`](#method.quit)
86+
/// - [`terminate`](#method.terminate)
87+
/// - [`user_defined_1`](#method.user_defined_1)
88+
/// - [`user_defined_2`](#method.user_defined_2)
89+
///
90+
/// If a listed signal is not available for the current target, the returned
91+
/// set will simply not include it.
8192
#[inline]
8293
#[must_use]
8394
pub const fn termination() -> Self {
84-
Self::new()
85-
.alarm()
86-
.hangup()
87-
.interrupt()
88-
.pipe()
89-
.quit()
90-
.terminate()
91-
.user_defined_1()
92-
.user_defined_2()
95+
#[allow(unused_mut)]
96+
let mut set = Self::new();
97+
98+
// This would make for an amazing use case of `#[cfg(accessible(...))]`.
99+
// See https://github.com/rust-lang/rust/issues/64797 for info on this.
100+
#[cfg(any(
101+
// According to `libc`:
102+
// "bsd"
103+
target_os = "macos",
104+
target_os = "ios",
105+
target_os = "freebsd",
106+
target_os = "dragonfly",
107+
target_os = "openbsd",
108+
target_os = "netbsd",
109+
// "linux-like"
110+
target_os = "linux",
111+
target_os = "android",
112+
target_os = "emscripten",
113+
// "solarish"
114+
target_os = "solaris",
115+
target_os = "illumos",
116+
// Uncategorized
117+
windows,
118+
target_os = "fuchsia",
119+
target_os = "redox",
120+
target_os = "haiku",
121+
target_os = "hermit",
122+
target_os = "vxworks",
123+
target_env = "uclibc",
124+
))]
125+
{
126+
#[cfg(not(windows))]
127+
{
128+
set = set.alarm().hangup().pipe().quit();
129+
}
130+
131+
#[cfg(any(
132+
not(target_env = "uclibc"),
133+
all(
134+
target_env = "uclibc",
135+
any(
136+
target_arch = "arm",
137+
target_arch = "mips",
138+
target_arch = "mips64",
139+
),
140+
),
141+
))]
142+
{
143+
set = set.user_defined_1().user_defined_2();
144+
}
145+
146+
set = set.interrupt().terminate();
147+
}
148+
149+
set
93150
}
94151

95152
/// Converts `self` into a raw signal set.

0 commit comments

Comments
 (0)