summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2021-06-12 13:12:10 -0600
committerAlan Somers <asomers@gmail.com>2021-07-07 20:49:29 -0600
commit2d796eba380e8f4e5d935b6b356c9d401917b92d (patch)
tree7b344bb84c5e8a6957f46490e151551b09ce7f1b
parent6511d02414ec9dd4bcaa237336c5f74869e6c41a (diff)
downloadnix-2d796eba380e8f4e5d935b6b356c9d401917b92d.zip
Collapse Error into Errno
Now that Nix's weird error types are eliminated, there's no reason not to simply use Errno as the Error type.
-rw-r--r--src/errno.rs74
-rw-r--r--src/lib.rs113
-rw-r--r--src/mount/bsd.rs11
-rw-r--r--src/pty.rs2
-rw-r--r--src/sys/aio.rs6
-rw-r--r--src/sys/ptrace/linux.rs4
-rw-r--r--src/sys/signalfd.rs2
-rw-r--r--src/sys/socket/mod.rs2
-rw-r--r--src/sys/timerfd.rs6
-rw-r--r--src/unistd.rs2
-rw-r--r--test/sys/test_aio.rs2
-rw-r--r--test/sys/test_ioctl.rs28
-rw-r--r--test/sys/test_lio_listio_resubmit.rs9
-rw-r--r--test/sys/test_ptrace.rs19
-rw-r--r--test/sys/test_signal.rs4
-rw-r--r--test/sys/test_socket.rs12
-rw-r--r--test/sys/test_termios.rs8
-rw-r--r--test/sys/test_wait.rs3
-rw-r--r--test/test_dir.rs2
-rw-r--r--test/test_fcntl.rs8
-rw-r--r--test/test_mq.rs15
-rw-r--r--test/test_nmount.rs2
-rw-r--r--test/test_poll.rs3
-rw-r--r--test/test_stat.rs4
-rw-r--r--test/test_unistd.rs10
25 files changed, 142 insertions, 209 deletions
diff --git a/src/errno.rs b/src/errno.rs
index df149f5b..00e20140 100644
--- a/src/errno.rs
+++ b/src/errno.rs
@@ -1,5 +1,6 @@
use cfg_if::cfg_if;
use libc::{c_int, c_void};
+use std::convert::TryFrom;
use std::{fmt, io, error};
use crate::{Error, Result};
@@ -48,6 +49,42 @@ pub fn errno() -> i32 {
}
impl Errno {
+ /// Convert this `Error` to an [`Errno`](enum.Errno.html).
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// # use nix::Error;
+ /// # use nix::errno::Errno;
+ /// let e = Error::from(Errno::EPERM);
+ /// assert_eq!(Some(Errno::EPERM), e.as_errno());
+ /// ```
+ #[deprecated(
+ since = "0.22.0",
+ note = "It's a no-op now; just delete it."
+ )]
+ pub fn as_errno(self) -> Option<Self> {
+ Some(self)
+ }
+
+ /// Create a nix Error from a given errno
+ #[deprecated(
+ since = "0.22.0",
+ note = "It's a no-op now; just delete it."
+ )]
+ pub fn from_errno(errno: Errno) -> Error {
+ Error::from(errno)
+ }
+
+ /// Create a new invalid argument error (`EINVAL`)
+ #[deprecated(
+ since = "0.22.0",
+ note = "Use Errno::EINVAL instead"
+ )]
+ pub fn invalid_argument() -> Error {
+ Errno::EINVAL
+ }
+
pub fn last() -> Self {
last()
}
@@ -64,25 +101,30 @@ impl Errno {
clear()
}
- pub(crate) fn result2<S: ErrnoSentinel + PartialEq<S>>(value: S)
- -> std::result::Result<S, Self>
- {
- if value == S::sentinel() {
- Err(Self::last())
- } else {
- Ok(value)
- }
- }
-
/// Returns `Ok(value)` if it does not contain the sentinel value. This
/// should not be used when `-1` is not the errno sentinel value.
pub fn result<S: ErrnoSentinel + PartialEq<S>>(value: S) -> Result<S> {
if value == S::sentinel() {
- Err(Error::from(Self::last()))
+ Err(Self::last())
} else {
Ok(value)
}
}
+
+ /// Backwards compatibility hack for Nix <= 0.21.0 users
+ ///
+ /// In older versions of Nix, `Error::Sys` was an enum variant. Now it's a
+ /// function, which is compatible with most of the former use cases of the
+ /// enum variant. But you should use `Error(Errno::...)` instead.
+ #[deprecated(
+ since = "0.22.0",
+ note = "Use Errno::... instead"
+ )]
+ #[allow(non_snake_case)]
+ #[inline]
+ pub fn Sys(errno: Errno) -> Error {
+ errno
+ }
}
/// The sentinel value indicates that a function failed and more detailed
@@ -125,6 +167,16 @@ impl From<Errno> for io::Error {
}
}
+impl TryFrom<io::Error> for Errno {
+ type Error = io::Error;
+
+ fn try_from(ioerror: io::Error) -> std::result::Result<Self, io::Error> {
+ ioerror.raw_os_error()
+ .map(Errno::from_i32)
+ .ok_or(ioerror)
+ }
+}
+
fn last() -> Errno {
Errno::from_i32(errno())
}
diff --git a/src/lib.rs b/src/lib.rs
index 9b4ff8a5..3b534a58 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -79,16 +79,15 @@ pub mod unistd;
use libc::{c_char, PATH_MAX};
-use std::convert::TryFrom;
-use std::{error, fmt, io, ptr, result};
+use std::{ptr, result};
use std::ffi::{CStr, OsStr};
use std::os::unix::ffi::OsStrExt;
use std::path::{Path, PathBuf};
-use errno::{Errno, ErrnoSentinel};
+use errno::Errno;
/// Nix Result Type
-pub type Result<T> = result::Result<T, Error>;
+pub type Result<T> = result::Result<T, Errno>;
/// Nix's main error type.
///
@@ -100,111 +99,7 @@ pub type Result<T> = result::Result<T, Error>;
/// * Small size
/// * Represents all of the system's errnos, instead of just the most common
/// ones.
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-pub struct Error(pub Errno);
-
-impl Error {
- /// Convert this `Error` to an [`Errno`](enum.Errno.html).
- ///
- /// # Example
- ///
- /// ```
- /// # use nix::Error;
- /// # use nix::errno::Errno;
- /// let e = Error::from(Errno::EPERM);
- /// assert_eq!(Some(Errno::EPERM), e.as_errno());
- /// ```
- #[deprecated(
- since = "0.22.0",
- note = "Use Error::into<Errno> instead"
- )]
- pub fn as_errno(self) -> Option<Errno> {
- Some(self.0)
- }
-
- /// Create a nix Error from a given errno
- #[deprecated(
- since = "0.22.0",
- note = "Use Error::from instead"
- )]
- pub fn from_errno(errno: Errno) -> Error {
- Error::from(errno)
- }
-
- /// Get the current errno and convert it to a nix Error
- pub fn last() -> Error {
- Error::from(Errno::last())
- }
-
- /// Create a new invalid argument error (`EINVAL`)
- #[deprecated(
- since = "0.22.0",
- note = "Use Error::from(Errno::EINVAL) instead"
- )]
- pub fn invalid_argument() -> Error {
- Error::from(Errno::EINVAL)
- }
-
- /// Returns `Ok(value)` if it does not contain the sentinel value. This
- /// should not be used when `-1` is not the errno sentinel value.
- pub(crate) fn result<S: ErrnoSentinel + PartialEq<S>>(value: S)
- -> std::result::Result<S, Error>
- {
- Errno::result2(value).map_err(Self::from)
- }
-
- /// Backwards compatibility hack for Nix <= 0.21.0 users
- ///
- /// In older versions of Nix, `Error::Sys` was an enum variant. Now it's a
- /// function, which is compatible with most of the former use cases of the
- /// enum variant. But you should use `Error(Errno::...)` instead.
- #[deprecated(
- since = "0.22.0",
- note = "Use Error(Errno::...) instead"
- )]
- #[allow(non_snake_case)]
- #[inline]
- pub fn Sys(errno: Errno) -> Error {
- Error::from(errno)
- }
-}
-
-impl fmt::Display for Error {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{:?}: {}", self.0, self.0.desc())
- }
-}
-
-impl error::Error for Error {}
-
-impl From<Errno> for Error {
- fn from(errno: Errno) -> Self {
- Self(errno)
- }
-}
-
-impl From<Error> for Errno {
- fn from(error: Error) -> Self {
- error.0
- }
-}
-
-impl TryFrom<io::Error> for Error {
- type Error = io::Error;
-
- fn try_from(ioerror: io::Error) -> std::result::Result<Self, io::Error> {
- ioerror.raw_os_error()
- .map(Errno::from_i32)
- .map(Error::from)
- .ok_or(ioerror)
- }
-}
-
-impl From<Error> for io::Error {
- fn from(error: Error) -> Self {
- Self::from_raw_os_error(error.0 as i32)
- }
-}
+pub type Error = Errno;
pub trait NixPath {
fn is_empty(&self) -> bool;
diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs
index 3ee1f068..01449081 100644
--- a/src/mount/bsd.rs
+++ b/src/mount/bsd.rs
@@ -1,4 +1,5 @@
use crate::{
+ Error,
Errno,
NixPath,
Result,
@@ -99,7 +100,7 @@ libc_bitflags!(
/// by `nmount(2)`.
#[derive(Debug)]
pub struct NmountError {
- errno: Errno,
+ errno: Error,
errmsg: Option<String>
}
@@ -109,14 +110,14 @@ impl NmountError {
self.errmsg.as_deref()
}
- /// Returns the inner [`Errno`]
- pub fn errno(&self) -> Errno {
+ /// Returns the inner [`Error`]
+ pub fn error(&self) -> Error {
self.errno
}
- fn new(errno: Errno, errmsg: Option<&CStr>) -> Self {
+ fn new(error: Error, errmsg: Option<&CStr>) -> Self {
Self {
- errno,
+ errno: error,
errmsg: errmsg.map(CStr::to_string_lossy).map(Cow::into_owned)
}
}
diff --git a/src/pty.rs b/src/pty.rs
index 72d1ceda..a8eb938d 100644
--- a/src/pty.rs
+++ b/src/pty.rs
@@ -70,7 +70,7 @@ impl Drop for PtyMaster {
// condition, which can cause confusing errors for future I/O
// operations.
let e = unistd::close(self.0);
- if e == Err(Error(Errno::EBADF)) {
+ if e == Err(Errno::EBADF) {
panic!("Closing an invalid file descriptor!");
};
}
diff --git a/src/sys/aio.rs b/src/sys/aio.rs
index f9d1dd87..b63affb8 100644
--- a/src/sys/aio.rs
+++ b/src/sys/aio.rs
@@ -983,13 +983,13 @@ impl<'a> LioCb<'a> {
// aiocb is complete; collect its status and don't resubmit
self.results[i] = Some(a.aio_return_unpinned());
},
- Err(Error(Errno::EAGAIN)) => {
+ Err(Errno::EAGAIN) => {
self.list.push(a as *mut AioCb<'a> as *mut libc::aiocb);
},
- Err(Error(Errno::EINPROGRESS)) => {
+ Err(Errno::EINPROGRESS) => {
// aiocb is was successfully queued; no need to do anything
},
- Err(Error(Errno::EINVAL)) => panic!(
+ Err(Errno::EINVAL) => panic!(
"AioCb was never submitted, or already finalized"),
_ => unreachable!()
}
diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs
index 3ac48097..4ac43936 100644
--- a/src/sys/ptrace/linux.rs
+++ b/src/sys/ptrace/linux.rs
@@ -2,7 +2,7 @@
use cfg_if::cfg_if;
use std::{mem, ptr};
-use crate::{Error, Result};
+use crate::Result;
use crate::errno::Errno;
use libc::{self, c_void, c_long, siginfo_t};
use crate::unistd::Pid;
@@ -180,7 +180,7 @@ fn ptrace_peek(request: Request, pid: Pid, addr: AddressType, data: *mut c_void)
libc::ptrace(request as RequestType, libc::pid_t::from(pid), addr, data)
};
match Errno::result(ret) {
- Ok(..) | Err(Error(Errno::UnknownErrno)) => Ok(ret),
+ Ok(..) | Err(Errno::UnknownErrno) => Ok(ret),
err @ Err(..) => err,
}
}
diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs
index 32245bc6..49811a1a 100644
--- a/src/sys/signalfd.rs
+++ b/src/sys/signalfd.rs
@@ -108,7 +108,7 @@ impl SignalFd {
match res {
Ok(SIGNALFD_SIGINFO_SIZE) => Ok(Some(unsafe { mem::transmute(buffer.assume_init()) })),
Ok(_) => unreachable!("partial read on signalfd"),
- Err(Error(Errno::EAGAIN)) => Ok(None),
+ Err(Errno::EAGAIN) => Ok(None),
Err(error) => Err(error)
}
}
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index ff64b73f..c222bdd7 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -1572,7 +1572,7 @@ pub fn recvfrom(sockfd: RawFd, buf: &mut [u8])
&mut len as *mut socklen_t))? as usize;
match sockaddr_storage_to_addr(&addr, len as usize) {
- Err(Error(Errno::ENOTCONN)) => Ok((ret, None)),
+ Err(Errno::ENOTCONN) => Ok((ret, None)),
Ok(addr) => Ok((ret, Some(addr))),
Err(e) => Err(e)
}
diff --git a/src/sys/timerfd.rs b/src/sys/timerfd.rs
index 3ae4ca32..44915be1 100644
--- a/src/sys/timerfd.rs
+++ b/src/sys/timerfd.rs
@@ -30,7 +30,7 @@
//! ```
use crate::sys::time::TimeSpec;
use crate::unistd::read;
-use crate::{errno::Errno, Error, Result};
+use crate::{errno::Errno, Result};
use bitflags::bitflags;
use libc::c_int;
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
@@ -259,7 +259,7 @@ impl TimerFd {
loop {
if let Err(e) = read(self.fd, &mut [0u8; 8]) {
match e {
- Error(Errno::EINTR) => continue,
+ Errno::EINTR => continue,
_ => return Err(e),
}
} else {
@@ -277,7 +277,7 @@ impl Drop for TimerFd {
let result = Errno::result(unsafe {
libc::close(self.fd)
});
- if let Err(Error(Errno::EBADF)) = result {
+ if let Err(Errno::EBADF) = result {
panic!("close of TimerFd encountered EBADF");
}
}
diff --git a/src/unistd.rs b/src/unistd.rs
index 35b36b7a..de3b0490 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1432,7 +1432,7 @@ pub fn getgroups() -> Result<Vec<Gid>> {
unsafe { groups.set_len(s as usize) };
return Ok(groups);
},
- Err(Error(Errno::EINVAL)) => {
+ Err(Errno::EINVAL) => {
// EINVAL indicates that the buffer size was too
// small, resize it up to ngroups_max as limit.
reserve_double_buffer_size(&mut groups, ngroups_max)
diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs
index f1d9a3b1..3208410e 100644
--- a/test/sys/test_aio.rs
+++ b/test/sys/test_aio.rs
@@ -177,7 +177,7 @@ fn test_aio_suspend() {
let cbbuf = [wcb.as_ref(), rcb.as_ref()];
let r = aio_suspend(&cbbuf[..], Some(timeout));
match r {
- Err(Error(Errno::EINTR)) => continue,
+ Err(Errno::EINTR) => continue,
Err(e) => panic!("aio_suspend returned {:?}", e),
Ok(_) => ()
};
diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs
index d65e43ac..236d2426 100644
--- a/test/sys/test_ioctl.rs
+++ b/test/sys/test_ioctl.rs
@@ -167,7 +167,6 @@ mod linux_ioctls {
use tempfile::tempfile;
use libc::{TCGETS, TCSBRK, TCSETS, TIOCNXCL, termios};
- use nix::Error;
use nix::errno::Errno;
ioctl_none_bad!(tiocnxcl, TIOCNXCL);
@@ -175,7 +174,7 @@ mod linux_ioctls {
fn test_ioctl_none_bad() {
let file = tempfile().unwrap();
let res = unsafe { tiocnxcl(file.as_raw_fd()) };
- assert_eq!(res, Err(Error(Errno::ENOTTY)));
+ assert_eq!(res, Err(Errno::ENOTTY));
}
ioctl_read_bad!(tcgets, TCGETS, termios);
@@ -184,7 +183,7 @@ mod linux_ioctls {
let file = tempfile().unwrap();
let mut termios = unsafe { mem::zeroed() };
let res = unsafe { tcgets(file.as_raw_fd(), &mut termios) };
- assert_eq!(res, Err(Error(Errno::ENOTTY)));
+ assert_eq!(res, Err(Errno::ENOTTY));
}
ioctl_write_int_bad!(tcsbrk, TCSBRK);
@@ -192,7 +191,7 @@ mod linux_ioctls {
fn test_ioctl_write_int_bad() {
let file = tempfile().unwrap();
let res = unsafe { tcsbrk(file.as_raw_fd(), 0) };
- assert_eq!(res, Err(Error(Errno::ENOTTY)));
+ assert_eq!(res, Err(Errno::ENOTTY));
}
ioctl_write_ptr_bad!(tcsets, TCSETS, termios);
@@ -201,7 +200,7 @@ mod linux_ioctls {
let file = tempfile().unwrap();
let termios: termios = unsafe { mem::zeroed() };
let res = unsafe { tcsets(file.as_raw_fd(), &termios) };
- assert_eq!(res, Err(Error(Errno::ENOTTY)));
+ assert_eq!(res, Err(Errno::ENOTTY));
}
// FIXME: Find a suitable example for `ioctl_readwrite_bad`
@@ -212,7 +211,7 @@ mod linux_ioctls {
fn test_ioctl_none() {
let file = tempfile().unwrap();
let res = unsafe { log_status(file.as_raw_fd()) };
- assert!(res == Err(Error(Errno::ENOTTY)) || res == Err(Error(Errno::ENOSYS)));
+ assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS));
}
#[repr(C)]
@@ -231,7 +230,7 @@ mod linux_ioctls {
let file = tempfile().unwrap();
let data: v4l2_audio = unsafe { mem::zeroed() };
let res = unsafe { s_audio(file.as_raw_fd(), &data) };
- assert!(res == Err(Error(Errno::ENOTTY)) || res == Err(Error(Errno::ENOSYS)));
+ assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS));
}
// From linux/net/bluetooth/hci_sock.h
@@ -242,7 +241,7 @@ mod linux_ioctls {
fn test_ioctl_write_int() {
let file = tempfile().unwrap();
let res = unsafe { hcidevup(file.as_raw_fd(), 0) };
- assert!(res == Err(Error(Errno::ENOTTY)) || res == Err(Error(Errno::ENOSYS)));
+ assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS));
}
// From linux/videodev2.h
@@ -252,7 +251,7 @@ mod linux_ioctls {
let file = tempfile().unwrap();
let mut data: v4l2_audio = unsafe { mem::zeroed() };
let res = unsafe { g_audio(file.as_raw_fd(), &mut data) };
- assert!(res == Err(Error(Errno::ENOTTY)) || res == Err(Error(Errno::ENOSYS)));
+ assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS));
}
// From linux/videodev2.h
@@ -262,7 +261,7 @@ mod linux_ioctls {
let file = tempfile().unwrap();
let mut data: v4l2_audio = unsafe { mem::zeroed() };
let res = unsafe { enum_audio(file.as_raw_fd(), &mut data) };
- assert!(res == Err(Error(Errno::ENOTTY)) || res == Err(Error(Errno::ENOSYS)));
+ assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS));
}
// FIXME: Find a suitable example for `ioctl_read_buf`.
@@ -288,7 +287,7 @@ mod linux_ioctls {
let file = tempfile().unwrap();
let data: [spi_ioc_transfer; 4] = unsafe { mem::zeroed() };
let res = unsafe { spi_ioc_message(file.as_raw_fd(), &data[..]) };
- assert!(res == Err(Error(Errno::ENOTTY)) || res == Err(Error(Errno::ENOSYS)));
+ assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS));
}
// FIXME: Find a suitable example for `ioctl_readwrite_buf`.
@@ -302,7 +301,6 @@ mod freebsd_ioctls {
use tempfile::tempfile;
use libc::termios;
- use nix::Error;
use nix::errno::Errno;
// From sys/sys/ttycom.h
@@ -316,7 +314,7 @@ mod freebsd_ioctls {
fn test_ioctl_none() {
let file = tempfile().unwrap();
let res = unsafe { tiocnxcl(file.as_raw_fd()) };
- assert_eq!(res, Err(Error(Errno::ENOTTY)));
+ assert_eq!(res, Err(Errno::ENOTTY));
}
ioctl_read!(tiocgeta, TTY_IOC_MAGIC, TTY_IOC_TYPE_GETA, termios);
@@ -325,7 +323,7 @@ mod freebsd_ioctls {
let file = tempfile().unwrap();
let mut termios = unsafe { mem::zeroed() };
let res = unsafe { tiocgeta(file.as_raw_fd(), &mut termios) };
- assert_eq!(res, Err(Error(Errno::ENOTTY)));
+ assert_eq!(res, Err(Errno::ENOTTY));
}
ioctl_write_ptr!(tiocseta, TTY_IOC_MAGIC, TTY_IOC_TYPE_SETA, termios);
@@ -334,6 +332,6 @@ mod freebsd_ioctls {
let file = tempfile().unwrap();
let termios: termios = unsafe { mem::zeroed() };
let res = unsafe { tiocseta(file.as_raw_fd(), &termios) };
- assert_eq!(res, Err(Error(Errno::ENOTTY)));
+ assert_eq!(res, Err(Errno::ENOTTY));
}
}
diff --git a/test/sys/test_lio_listio_resubmit.rs b/test/sys/test_lio_listio_resubmit.rs
index 1c1941fb..c9077891 100644
--- a/test/sys/test_lio_listio_resubmit.rs
+++ b/test/sys/test_lio_listio_resubmit.rs
@@ -4,7 +4,6 @@
// we must disable the test here rather than in Cargo.toml
#![cfg(target_os = "freebsd")]
-use nix::Error;
use nix::errno::*;
use nix::libc::off_t;
use nix::sys::aio::*;
@@ -25,7 +24,7 @@ fn finish_liocb(liocb: &mut LioCb) {
let e = liocb.error(j);
match e {
Ok(()) => break,
- Err(Error(Errno::EINPROGRESS)) =>
+ Err(Errno::EINPROGRESS) =>
thread::sleep(time::Duration::from_millis(10)),
Err(x) => panic!("aio_error({:?})", x)
}
@@ -82,9 +81,9 @@ fn test_lio_listio_resubmit() {
}
let mut liocb = builder.finish();
let mut err = liocb.listio(LioMode::LIO_NOWAIT, SigevNotify::SigevNone);
- while err == Err(Error(Errno::EIO)) ||
- err == Err(Error(Errno::EAGAIN)) ||
- err == Err(Error(Errno::EINTR)) {
+ while err == Err(Errno::EIO) ||
+ err == Err(Errno::EAGAIN) ||
+ err == Err(Errno::EINTR) {
//
thread::sleep(time::Duration::from_millis(10));
resubmit_count += 1;
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs
index b8309a74..985945d1 100644
--- a/test/sys/test_ptrace.rs
+++ b/test/sys/test_ptrace.rs
@@ -1,4 +1,3 @@
-use nix::Error;
use nix::errno::Errno;
use nix::unistd::getpid;
use nix::sys::ptrace;
@@ -16,8 +15,8 @@ fn test_ptrace() {
// FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS
require_capability!(CAP_SYS_PTRACE);
let err = ptrace::attach(getpid()).unwrap_err();
- assert!(err == Error(Errno::EPERM) || err == Error(Errno::EINVAL) ||
- err == Error(Errno::ENOSYS));
+ assert!(err == Errno::EPERM || err == Errno::EINVAL ||
+ err == Errno::ENOSYS);
}
// Just make sure ptrace_setoptions can be called at all, for now.
@@ -26,7 +25,7 @@ fn test_ptrace() {
fn test_ptrace_setoptions() {
require_capability!(CAP_SYS_PTRACE);
let err = ptrace::setoptions(getpid(), Options::PTRACE_O_TRACESYSGOOD).unwrap_err();
- assert!(err != Error(Errno::EOPNOTSUPP));
+ assert!(err != Errno::EOPNOTSUPP);
}
// Just make sure ptrace_getevent can be called at all, for now.
@@ -35,7 +34,7 @@ fn test_ptrace_setoptions() {
fn test_ptrace_getevent() {
require_capability!(CAP_SYS_PTRACE);
let err = ptrace::getevent(getpid()).unwrap_err();
- assert!(err != Error(Errno::EOPNOTSUPP));
+ assert!(err != Errno::EOPNOTSUPP);
}
// Just make sure ptrace_getsiginfo can be called at all, for now.
@@ -43,8 +42,8 @@ fn test_ptrace_getevent() {
#[cfg(any(target_os = "android", target_os = "linux"))]
fn test_ptrace_getsiginfo() {
require_capability!(CAP_SYS_PTRACE);
- if let Err(Error(Errno::EOPNOTSUPP)) = ptrace::getsiginfo(getpid()) {
- panic!("ptrace_getsiginfo returns Error(Errno::EOPNOTSUPP)!");
+ if let Err(Errno::EOPNOTSUPP) = ptrace::getsiginfo(getpid()) {
+ panic!("ptrace_getsiginfo returns Errno::EOPNOTSUPP!");
}
}
@@ -54,8 +53,8 @@ fn test_ptrace_getsiginfo() {
fn test_ptrace_setsiginfo() {
require_capability!(CAP_SYS_PTRACE);
let siginfo = unsafe { mem::zeroed() };
- if let Err(Error(Errno::EOPNOTSUPP)) = ptrace::setsiginfo(getpid(), &siginfo) {
- panic!("ptrace_setsiginfo returns Error(Errno::EOPNOTSUPP)!");
+ if let Err(Errno::EOPNOTSUPP) = ptrace::setsiginfo(getpid(), &siginfo) {
+ panic!("ptrace_setsiginfo returns Errno::EOPNOTSUPP!");
}
}
@@ -79,7 +78,7 @@ fn test_ptrace_cont() {
// On valid platforms the ptrace call should return Errno::EPERM, this
// is already tested by `test_ptrace`.
let err = ptrace::attach(getpid()).unwrap_err();
- if err == Error(Errno::ENOSYS) {
+ if err == Errno::ENOSYS {
return;
}
diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs
index 741d97b9..1b89af57 100644
--- a/test/sys/test_signal.rs
+++ b/test/sys/test_signal.rs
@@ -1,5 +1,5 @@
#[cfg(not(target_os = "redox"))]
-use nix::{errno::Errno, Error};
+use nix::errno::Errno;
use nix::sys::signal::*;
use nix::unistd::*;
use std::convert::TryFrom;
@@ -92,7 +92,7 @@ fn test_signal_sigaction() {
let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
let action_handler = SigHandler::SigAction(test_sigaction_action);
- assert_eq!(unsafe { signal(Signal::SIGINT, action_handler) }.unwrap_err(), Error(Errno::ENOTSUP));
+ assert_eq!(unsafe { signal(Signal::SIGINT, action_handler) }.unwrap_err(), Errno::ENOTSUP);
}
#[test]
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index c833aa7c..b6b52785 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -519,7 +519,6 @@ mod recvfrom {
// Test error handling of our recvmsg wrapper
#[test]
pub fn test_recvmsg_ebadf() {
- use nix::Error;
use nix::errno::Errno;
use nix::sys::socket::{MsgFlags, recvmsg};
use nix::sys::uio::IoVec;
@@ -528,7 +527,7 @@ pub fn test_recvmsg_ebadf() {
let iov = [IoVec::from_mut_slice(&mut buf[..])];
let fd = -1; // Bad file descriptor
let r = recvmsg(fd, &iov, None, MsgFlags::empty());
- assert_eq!(r.err().unwrap(), Error(Errno::EBADF));
+ assert_eq!(r.err().unwrap(), Errno::EBADF);
}
// Disable the test on emulated platforms due to a bug in QEMU versions <
@@ -818,7 +817,6 @@ pub fn test_sendmsg_ipv4packetinfo() {
target_os = "freebsd"))]
#[test]
pub fn test_sendmsg_ipv6packetinfo() {
- use nix::Error;
use nix::errno::Errno;
use nix::sys::uio::IoVec;
use nix::sys::socket::{socket, sendmsg, bind,
@@ -835,7 +833,7 @@ pub fn test_sendmsg_ipv6packetinfo() {
let inet_addr = InetAddr::from_std(&std_sa);
let sock_addr = SockAddr::new_inet(inet_addr);
- if let Err(Error(Errno::EADDRNOTAVAIL)) = bind(sock, &sock_addr) {
+ if let Err(Errno::EADDRNOTAVAIL) = bind(sock, &sock_addr) {
println!("IPv6 not available, skipping test.");
return;
}
@@ -1145,7 +1143,6 @@ pub fn test_unixdomain() {
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[test]
pub fn test_syscontrol() {
- use nix::Error;
use nix::errno::Errno;
use nix::sys::socket::{socket, SockAddr, SockType, SockFlag, SockProtocol};
@@ -1153,7 +1150,7 @@ pub fn test_syscontrol() {
SockFlag::empty(), SockProtocol::KextControl)
.expect("socket failed");
let _sockaddr = SockAddr::new_sys_control(fd, "com.apple.net.utun_control", 0).expect("resolving sys_control name failed");
- assert_eq!(SockAddr::new_sys_control(fd, "foo.bar.lol", 0).err(), Some(Error(Errno::ENOENT)));
+ assert_eq!(SockAddr::new_sys_control(fd, "foo.bar.lol", 0).err(), Some(Errno::ENOENT));
// requires root privileges
// connect(fd, &sockaddr).expect("connect failed");
@@ -1500,7 +1497,6 @@ pub fn test_recv_ipv6pktinfo() {
#[test]
pub fn test_vsock() {
use libc;
- use nix::Error;
use nix::errno::Errno;
use nix::sys::socket::{AddressFamily, socket, bind, connect, listen,
SockAddr, SockType, SockFlag};
@@ -1516,7 +1512,7 @@ pub fn test_vsock() {
// VMADDR_CID_HYPERVISOR is reserved, so we expect an EADDRNOTAVAIL error.
let sockaddr = SockAddr::new_vsock(libc::VMADDR_CID_HYPERVISOR, port);
assert_eq!(bind(s1, &sockaddr).err(),
- Some(Error(Errno::EADDRNOTAVAIL)));
+ Some(Errno::EADDRNOTAVAIL));
let sockaddr = SockAddr::new_vsock(libc::VMADDR_CID_ANY, port);
assert_eq!(bind(s1, &sockaddr), Ok(()));
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index ce436a13..63d6a51f 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -1,7 +1,7 @@
use std::os::unix::prelude::*;
use tempfile::tempfile;
-use nix::{Error, fcntl};
+use nix::fcntl;
use nix::errno::Errno;
use nix::pty::openpty;
use nix::sys::termios::{self, LocalFlags, OutputFlags, tcgetattr};
@@ -32,14 +32,14 @@ fn test_tcgetattr_pty() {
fn test_tcgetattr_enotty() {
let file = tempfile().unwrap();
assert_eq!(termios::tcgetattr(file.as_raw_fd()).err(),
- Some(Error(Errno::ENOTTY)));
+ Some(Errno::ENOTTY));
}
// Test tcgetattr on an invalid file descriptor
#[test]
fn test_tcgetattr_ebadf() {
assert_eq!(termios::tcgetattr(-1).err(),
- Some(Error(Errno::EBADF)));
+ Some(Errno::EBADF));
}
// Test modifying output flags
@@ -126,5 +126,5 @@ fn test_local_flags() {
let read = read(pty.master, &mut buf).unwrap_err();
close(pty.master).unwrap();
close(pty.slave).unwrap();
- assert_eq!(read, Error(Errno::EAGAIN));
+ assert_eq!(read, Errno::EAGAIN);
}
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 65220474..2d26fb8e 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -1,5 +1,4 @@
use nix::errno::Errno;
-use nix::Error;
use nix::unistd::*;
use nix::unistd::ForkResult::*;
use nix::sys::signal::*;
@@ -42,7 +41,7 @@ fn test_waitstatus_from_raw() {
let pid = Pid::from_raw(1);
assert_eq!(WaitStatus::from_raw(pid, 0x0002), Ok(WaitStatus::Signaled(pid, Signal::SIGINT, false)));
assert_eq!(WaitStatus::from_raw(pid, 0x0200), Ok(WaitStatus::Exited(pid, 2)));
- assert_eq!(WaitStatus::from_raw(pid, 0x7f7f), Err(Error(Errno::EINVAL)));
+ assert_eq!(WaitStatus::from_raw(pid, 0x7f7f), Err(Errno::EINVAL));
}
#[test]
diff --git a/test/test_dir.rs b/test/test_dir.rs
index 91556034..0dc7308e 100644
--- a/test/test_dir.rs
+++ b/test/test_dir.rs
@@ -51,5 +51,5 @@ fn rewind() {
#[test]
fn ebadf() {
- assert_eq!(Dir::from_fd(-1).unwrap_err(), nix::Error(nix::errno::Errno::EBADF));
+ assert_eq!(Dir::from_fd(-1).unwrap_err(), nix::Error::EBADF);
}
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index 7651c909..18b73481 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -1,6 +1,4 @@
#[cfg(not(target_os = "redox"))]
-use nix::Error;
-#[cfg(not(target_os = "redox"))]
use nix::errno::*;
#[cfg(not(target_os = "redox"))]
use nix::fcntl::{open, OFlag, readlink};
@@ -55,7 +53,7 @@ fn test_renameat() {
let new_dirfd = open(new_dir.path(), OFlag::empty(), Mode::empty()).unwrap();
renameat(Some(old_dirfd), "old", Some(new_dirfd), "new").unwrap();
assert_eq!(renameat(Some(old_dirfd), "old", Some(new_dirfd), "new").unwrap_err(),
- Error(Errno::ENOENT));
+ Errno::ENOENT);
close(old_dirfd).unwrap();
close(new_dirfd).unwrap();
assert!(new_dir.path().join("new").exists());
@@ -385,7 +383,7 @@ mod test_posix_fallocate {
assert_eq!(tmp.read(&mut data).expect("read failure"), LEN);
assert_eq!(&data[..], &[0u8; LEN][..]);
}
- Err(nix::Error(Errno::EINVAL)) => {
+ Err(Errno::EINVAL) => {
// POSIX requires posix_fallocate to return EINVAL both for
// invalid arguments (i.e. len < 0) and if the operation is not
// supported by the file system.
@@ -401,7 +399,7 @@ mod test_posix_fallocate {
fn errno() {
let (rd, _wr) = pipe().unwrap();
let err = posix_fallocate(rd as RawFd, 0, 100).unwrap_err();
- match err.0 {
+ match err {
Errno::EINVAL | Errno::ENODEV | Errno::ESPIPE | Errno::EBADF => (),
errno =>
panic!(
diff --git a/test/test_mq.rs b/test/test_mq.rs
index e16103fb..d0826923 100644
--- a/test/test_mq.rs
+++ b/test/test_mq.rs
@@ -2,7 +2,6 @@ use std::ffi::CString;
use std::str;
use nix::errno::Errno;
-use nix::Error;
use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_attr_member_t};
use nix::mqueue::{MqAttr, MQ_OFlag};
use nix::sys::stat::Mode;
@@ -16,7 +15,7 @@ fn test_mq_send_and_receive() {
let oflag0 = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r0 = mq_open(mq_name, oflag0, mode, Some(&attr));
- if let Err(Error(Errno::ENOSYS)) = r0 {
+ if let Err(Errno::ENOSYS) = r0 {
println!("message queues not supported or module not loaded?");
return;
};
@@ -47,7 +46,7 @@ fn test_mq_getattr() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name, oflag, mode, Some(&initial_attr));
- if let Err(Error(Errno::ENOSYS)) = r {
+ if let Err(Errno::ENOSYS) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -70,7 +69,7 @@ fn test_mq_setattr() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name, oflag, mode, Some(&initial_attr));
- if let Err(Error(Errno::ENOSYS)) = r {
+ if let Err(Errno::ENOSYS) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -107,7 +106,7 @@ fn test_mq_set_nonblocking() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name, oflag, mode, Some(&initial_attr));
- if let Err(Error(Errno::ENOSYS)) = r {
+ if let Err(Errno::ENOSYS) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -132,7 +131,7 @@ fn test_mq_unlink() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name_opened, oflag, mode, Some(&initial_attr));
- if let Err(Error(Errno::ENOSYS)) = r {
+ if let Err(Errno::ENOSYS) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -142,9 +141,9 @@ fn test_mq_unlink() {
assert_eq!(res_unlink, Ok(()) );
let res_unlink_not_opened = mq_unlink(mq_name_not_opened);
- assert_eq!(res_unlink_not_opened, Err(Error(Errno::ENOENT)) );
+ assert_eq!(res_unlink_not_opened, Err(Errno::ENOENT) );
mq_close(mqd).unwrap();
let res_unlink_after_close = mq_unlink(mq_name_opened);
- assert_eq!(res_unlink_after_close, Err(Error(Errno::ENOENT)) );
+ assert_eq!(res_unlink_after_close, Err(Errno::ENOENT) );
}
diff --git a/test/test_nmount.rs b/test/test_nmount.rs
index 92f459d6..4c74ecf6 100644
--- a/test/test_nmount.rs
+++ b/test/test_nmount.rs
@@ -46,6 +46,6 @@ fn bad_fstype() {
.str_opt_owned("target", target.path().to_str().unwrap())
.nmount(MntFlags::empty()).unwrap_err();
- assert_eq!(e.errno(), Errno::EINVAL);
+ assert_eq!(e.error(), Errno::EINVAL);
assert_eq!(e.errmsg(), Some("Invalid fstype"));
}
diff --git a/test/test_poll.rs b/test/test_poll.rs
index 0e2da61a..0395512b 100644
--- a/test/test_poll.rs
+++ b/test/test_poll.rs
@@ -1,5 +1,4 @@
use nix::{
- Error,
errno::Errno,
poll::{PollFlags, poll, PollFd},
unistd::{write, pipe}
@@ -10,7 +9,7 @@ macro_rules! loop_while_eintr {
loop {
match $poll_expr {
Ok(nfds) => break nfds,
- Err(Error(Errno::EINTR)) => (),
+ Err(Errno::EINTR) => (),
Err(e) => panic!("{}", e)
}
}
diff --git a/test/test_stat.rs b/test/test_stat.rs
index d6bf5215..424371fa 100644
--- a/test/test_stat.rs
+++ b/test/test_stat.rs
@@ -15,7 +15,7 @@ use libc::{S_IFMT, S_IFLNK};
use libc::mode_t;
#[cfg(not(target_os = "redox"))]
-use nix::{fcntl, Error};
+use nix::fcntl;
#[cfg(not(target_os = "redox"))]
use nix::errno::Errno;
#[cfg(not(target_os = "redox"))]
@@ -304,5 +304,5 @@ fn test_mkdirat_fail() {
let dirfd = fcntl::open(&tempdir.path().join(not_dir_filename), fcntl::OFlag::O_CREAT,
stat::Mode::empty()).unwrap();
let result = mkdirat(dirfd, filename, Mode::S_IRWXU).unwrap_err();
- assert_eq!(result, Error(Errno::ENOTDIR));
+ assert_eq!(result, Errno::ENOTDIR);
}
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 17eef590..b95f1549 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -10,8 +10,6 @@ use nix::sys::stat::{self, Mode, SFlag};
#[cfg(not(any(target_os = "redox", target_os = "fuchsia")))]
use nix::pty::{posix_openpt, grantpt, unlockpt, ptsname};
use nix::errno::Errno;
-#[cfg(not(target_os = "redox"))]
-use nix::Error;
use std::{env, iter};
#[cfg(not(any(target_os = "fuchsia", target_os = "redox")))]
use std::ffi::CString;
@@ -972,7 +970,7 @@ fn test_unlinkat_dir_noremovedir() {
// Attempt unlink dir at relative path without proper flag
let err_result = unlinkat(Some(dirfd), dirname, UnlinkatFlags::NoRemoveDir).unwrap_err();
- assert!(err_result == Error(Errno::EISDIR) || err_result == Error(Errno::EPERM));
+ assert!(err_result == Errno::EISDIR || err_result == Errno::EPERM);
}
#[test]
@@ -1016,7 +1014,7 @@ fn test_access_not_existing() {
let tempdir = tempdir().unwrap();
let dir = tempdir.path().join("does_not_exist.txt");
assert_eq!(access(&dir, AccessFlags::F_OK).err().unwrap(),
- Error(Errno::ENOENT));
+ Errno::ENOENT);
}
#[test]
@@ -1094,13 +1092,13 @@ fn test_ttyname() {
fn test_ttyname_not_pty() {
let fd = File::open("/dev/zero").unwrap();
assert!(fd.as_raw_fd() > 0);
- assert_eq!(ttyname(fd.as_raw_fd()), Err(Error(Errno::ENOTTY)));
+ assert_eq!(ttyname(fd.as_raw_fd()), Err(Errno::ENOTTY));
}
#[test]
#[cfg(not(any(target_os = "redox", target_os = "fuchsia")))]
fn test_ttyname_invalid_fd() {
- assert_eq!(ttyname(-1), Err(Error(Errno::EBADF)));
+ assert_eq!(ttyname(-1), Err(Errno::EBADF));
}
#[test]