summaryrefslogtreecommitdiff
path: root/src/sys/signal.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-08-11 00:11:52 +0000
committerGitHub <noreply@github.com>2021-08-11 00:11:52 +0000
commita7e86b2fda0109d0806b9159f9294cdc15b3eb21 (patch)
tree4f3661247ac078eb37c513d1a19e5428e63bf254 /src/sys/signal.rs
parent2df8679237b833955d2fe7605307673a85760a6f (diff)
parent9df5abfab1f315d87bdacf226380d532318e9bfb (diff)
downloadnix-a7e86b2fda0109d0806b9159f9294cdc15b3eb21.zip
Merge #1484
1484: Optionally implement TryFrom in libc_enum! r=asomers a=asomers This saves code in several separate places that need to do this separately. At the same time, remove a few uses of mem::transmute that were implementing TryFrom or similar functionality. Issue #373 Co-authored-by: Alan Somers <asomers@gmail.com>
Diffstat (limited to 'src/sys/signal.rs')
-rw-r--r--src/sys/signal.rs18
1 files changed, 3 insertions, 15 deletions
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index cbd5cfbe..e68ebf16 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -6,7 +6,6 @@
use crate::{Error, Result};
use crate::errno::Errno;
use crate::unistd::Pid;
-use std::convert::TryFrom;
use std::mem;
use std::fmt;
use std::str::FromStr;
@@ -71,6 +70,7 @@ libc_enum!{
target_os = "redox")))]
SIGINFO,
}
+ impl TryFrom<i32>
}
impl FromStr for Signal {
@@ -335,8 +335,6 @@ const SIGNALS: [Signal; 31] = [
SIGEMT,
SIGINFO];
-pub const NSIG: libc::c_int = 32;
-
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct SignalIterator {
next: usize,
@@ -362,18 +360,6 @@ impl Signal {
}
}
-impl TryFrom<libc::c_int> for Signal {
- type Error = Error;
-
- fn try_from(signum: libc::c_int) -> Result<Signal> {
- if 0 < signum && signum < NSIG {
- Ok(unsafe { mem::transmute(signum) })
- } else {
- Err(Error::from(Errno::EINVAL))
- }
- }
-}
-
pub const SIGIOT : Signal = SIGABRT;
pub const SIGPOLL : Signal = SIGIO;
pub const SIGUNUSED : Signal = SIGSYS;
@@ -489,6 +475,8 @@ impl SigSet {
/// signal mask becomes pending, and returns the accepted signal.
#[cfg(not(target_os = "redox"))] // RedoxFS does not yet support sigwait
pub fn wait(&self) -> Result<Signal> {
+ use std::convert::TryFrom;
+
let mut signum = mem::MaybeUninit::uninit();
let res = unsafe { libc::sigwait(&self.sigset as *const libc::sigset_t, signum.as_mut_ptr()) };