summaryrefslogtreecommitdiff
path: root/src/sys/signal.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/signal.rs')
-rw-r--r--src/sys/signal.rs46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 61bdc74a..f85bf266 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -5,7 +5,6 @@
use crate::{Error, Result};
use crate::errno::Errno;
-use crate::unistd::Pid;
use std::mem;
use std::fmt;
use std::str::FromStr;
@@ -14,8 +13,10 @@ use std::os::unix::io::RawFd;
use std::ptr;
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
+#[cfg(any(feature = "aio", feature = "signal"))]
pub use self::sigevent::*;
+#[cfg(any(feature = "aio", feature = "process", feature = "signal"))]
libc_enum!{
/// Types of operating system signals
// Currently there is only one definition of c_int in libc, as well as only one
@@ -24,6 +25,7 @@ libc_enum!{
// this is not (yet) possible.
#[repr(i32)]
#[non_exhaustive]
+ #[cfg_attr(docsrs, doc(cfg(any(feature = "aio", feature = "signal"))))]
pub enum Signal {
/// Hangup
SIGHUP,
@@ -89,6 +91,7 @@ libc_enum!{
SIGIO,
#[cfg(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// Power failure imminent.
SIGPWR,
/// Bad system call
@@ -96,17 +99,20 @@ libc_enum!{
#[cfg(not(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux",
target_os = "redox")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// Emulator trap
SIGEMT,
#[cfg(not(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux",
target_os = "redox")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// Information request
SIGINFO,
}
impl TryFrom<i32>
}
+#[cfg(feature = "signal")]
impl FromStr for Signal {
type Err = Error;
fn from_str(s: &str) -> Result<Signal> {
@@ -161,6 +167,7 @@ impl FromStr for Signal {
}
}
+#[cfg(feature = "signal")]
impl Signal {
/// Returns name of signal.
///
@@ -217,21 +224,25 @@ impl Signal {
}
}
+#[cfg(feature = "signal")]
impl AsRef<str> for Signal {
fn as_ref(&self) -> &str {
self.as_str()
}
}
+#[cfg(feature = "signal")]
impl fmt::Display for Signal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.as_ref())
}
}
+#[cfg(feature = "signal")]
pub use self::Signal::*;
#[cfg(target_os = "redox")]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 29] = [
SIGHUP,
SIGINT,
@@ -266,6 +277,7 @@ const SIGNALS: [Signal; 29] = [
target_os = "emscripten", target_os = "fuchsia"),
not(any(target_arch = "mips", target_arch = "mips64",
target_arch = "sparc64"))))]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
@@ -302,6 +314,7 @@ const SIGNALS: [Signal; 31] = [
target_os = "emscripten", target_os = "fuchsia"),
any(target_arch = "mips", target_arch = "mips64",
target_arch = "sparc64")))]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 30] = [
SIGHUP,
SIGINT,
@@ -336,6 +349,7 @@ const SIGNALS: [Signal; 30] = [
#[cfg(not(any(target_os = "linux", target_os = "android",
target_os = "fuchsia", target_os = "emscripten",
target_os = "redox")))]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
@@ -369,6 +383,9 @@ const SIGNALS: [Signal; 31] = [
SIGEMT,
SIGINFO];
+feature! {
+#![feature = "signal"]
+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
/// Iterate through all signals defined by this operating system
pub struct SignalIterator {
@@ -407,9 +424,12 @@ pub const SIGUNUSED : Signal = SIGSYS;
type SaFlags_t = libc::c_int;
#[cfg(target_os = "redox")]
type SaFlags_t = libc::c_ulong;
+}
+#[cfg(feature = "signal")]
libc_bitflags!{
/// Controls the behavior of a [`SigAction`]
+ #[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
pub struct SaFlags: SaFlags_t {
/// When catching a [`Signal::SIGCHLD`] signal, the signal will be
/// generated only when a child process exits, not when a child process
@@ -435,10 +455,12 @@ libc_bitflags!{
}
}
+#[cfg(feature = "signal")]
libc_enum! {
/// Specifies how certain functions should manipulate a signal mask
#[repr(i32)]
#[non_exhaustive]
+ #[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
pub enum SigmaskHow {
/// The new mask is the union of the current mask and the specified set.
SIG_BLOCK,
@@ -450,13 +472,17 @@ libc_enum! {
}
}
+feature! {
+#![feature = "signal"]
+
+use crate::unistd::Pid;
+
/// Specifies a set of [`Signal`]s that may be blocked, waited for, etc.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct SigSet {
sigset: libc::sigset_t
}
-
impl SigSet {
/// Initialize to include all signals.
pub fn all() -> SigSet {
@@ -542,6 +568,7 @@ impl SigSet {
/// Suspends execution of the calling thread until one of the signals in the
/// signal mask becomes pending, and returns the accepted signal.
#[cfg(not(target_os = "redox"))] // RedoxFS does not yet support sigwait
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn wait(&self) -> Result<Signal> {
use std::convert::TryFrom;
@@ -573,6 +600,7 @@ pub enum SigHandler {
/// Use the given signal-catching function, which takes in the signal, information about how
/// the signal was generated, and a pointer to the threads `ucontext_t`.
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SigAction(extern fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void))
}
@@ -636,6 +664,7 @@ impl SigAction {
/// Returns the action's handler.
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn handler(&self) -> SigHandler {
match self.sigaction.sa_sigaction {
libc::SIG_DFL => SigHandler::SigDfl,
@@ -670,6 +699,7 @@ impl SigAction {
/// Returns the action's handler.
#[cfg(target_os = "redox")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn handler(&self) -> SigHandler {
match self.sigaction.sa_handler {
libc::SIG_DFL => SigHandler::SigDfl,
@@ -912,7 +942,11 @@ pub fn raise(signal: Signal) -> Result<()> {
Errno::result(res).map(drop)
}
+}
+
+feature! {
+#![any(feature = "aio", feature = "signal")]
/// Identifies a thread for [`SigevNotify::SigevThreadId`]
#[cfg(target_os = "freebsd")]
@@ -942,6 +976,7 @@ pub enum SigevNotify {
// expose a way to set the union members needed by SIGEV_THREAD.
/// Notify by delivering an event to a kqueue.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SigevKevent {
/// File descriptor of the kqueue to notify.
kq: RawFd,
@@ -950,6 +985,7 @@ pub enum SigevNotify {
},
/// Notify by delivering a signal to a thread.
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SigevThreadId {
/// Signal to send
signal: Signal,
@@ -960,9 +996,14 @@ pub enum SigevNotify {
si_value: libc::intptr_t
},
}
+}
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
mod sigevent {
+ feature! {
+ #![any(feature = "aio", feature = "signal")]
+
use std::mem;
use std::ptr;
use super::SigevNotify;
@@ -1051,6 +1092,7 @@ mod sigevent {
SigEvent{ sigevent: *sigevent }
}
}
+ }
}
#[cfg(test)]