diff --git a/Cargo.toml b/Cargo.toml index e985c8c0b0..b5c017f7fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "nix" description = "Rust friendly bindings to *nix APIs" +edition = "2018" version = "0.17.0" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix" @@ -57,6 +58,6 @@ name = "test-mount" path = "test/test_mount.rs" harness = false -[[target.'cfg(not(target_os = "redox"))'.test]] +[[test]] name = "test-ptymaster-drop" path = "test/test_ptymaster_drop.rs" diff --git a/README.md b/README.md index 123f33c466..ecf5bc941e 100644 --- a/README.md +++ b/README.md @@ -88,19 +88,13 @@ Tier 3: `nix` requires Rust 1.36.0 or newer. -To use `nix`, first add this to your `Cargo.toml`: +To use `nix`, add this to your `Cargo.toml`: ```toml [dependencies] nix = "0.17.0" ``` -Then, add this to your crate root: - -```rust,ignore -extern crate nix; -``` - ## Contributing Contributions are very welcome. Please See [CONTRIBUTING](CONTRIBUTING.md) for diff --git a/build.rs b/build.rs index 92fd3667fa..c527748b31 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,3 @@ -#[cfg(target_os = "dragonfly")] -extern crate cc; - #[cfg(target_os = "dragonfly")] fn main() { cc::Build::new() diff --git a/src/dir.rs b/src/dir.rs index be1201f21c..1d48f18c56 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -1,11 +1,10 @@ -use {Error, NixPath, Result}; -use errno::Errno; -use fcntl::{self, OFlag}; -use libc; +use crate::{Error, NixPath, Result}; +use crate::errno::Errno; +use crate::fcntl::{self, OFlag}; use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; use std::ptr; use std::ffi; -use sys; +use crate::sys; #[cfg(target_os = "linux")] use libc::{dirent64 as dirent, readdir64_r as readdir_r}; diff --git a/src/env.rs b/src/env.rs index 0d815be91e..f144dfedd0 100644 --- a/src/env.rs +++ b/src/env.rs @@ -1,4 +1,5 @@ -use {Error, Result}; +use cfg_if::cfg_if; +use crate::{Error, Result}; /// Clear the environment of all name-value pairs. /// diff --git a/src/errno.rs b/src/errno.rs index 730160f26d..1fb66ac5f7 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -1,8 +1,8 @@ +use cfg_if::cfg_if; #[cfg(not(target_os = "dragonfly"))] -use libc; use libc::{c_int, c_void}; use std::{fmt, io, error}; -use {Error, Result}; +use crate::{Error, Result}; pub use self::consts::*; @@ -584,8 +584,6 @@ fn desc(errno: Errno) -> &'static str { #[cfg(any(target_os = "linux", target_os = "android"))] mod consts { - use libc; - #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] pub enum Errno { @@ -873,8 +871,6 @@ mod consts { #[cfg(any(target_os = "macos", target_os = "ios"))] mod consts { - use libc; - #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] pub enum Errno { @@ -1110,8 +1106,6 @@ mod consts { #[cfg(target_os = "freebsd")] mod consts { - use libc; - #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] pub enum Errno { @@ -1328,8 +1322,6 @@ mod consts { #[cfg(target_os = "dragonfly")] mod consts { - use libc; - #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] pub enum Errno { @@ -1543,8 +1535,6 @@ mod consts { #[cfg(target_os = "openbsd")] mod consts { - use libc; - #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] pub enum Errno { @@ -1757,8 +1747,6 @@ mod consts { #[cfg(target_os = "netbsd")] mod consts { - use libc; - #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] pub enum Errno { @@ -1973,8 +1961,6 @@ mod consts { #[cfg(target_os = "redox")] mod consts { - use libc; - #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] pub enum Errno { diff --git a/src/fcntl.rs b/src/fcntl.rs index 06b79e4483..ea0364270c 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -1,17 +1,17 @@ -use errno::Errno; +use crate::errno::Errno; use libc::{self, c_char, c_int, c_uint, size_t, ssize_t}; use std::ffi::OsString; #[cfg(not(target_os = "redox"))] use std::os::raw; use std::os::unix::ffi::OsStringExt; use std::os::unix::io::RawFd; -use sys::stat::Mode; -use {NixPath, Result}; +use crate::sys::stat::Mode; +use crate::{NixPath, Result}; #[cfg(any(target_os = "android", target_os = "linux"))] use std::ptr; // For splice and copy_file_range #[cfg(any(target_os = "android", target_os = "linux"))] -use sys::uio::IoVec; // For vmsplice +use crate::sys::uio::IoVec; // For vmsplice #[cfg(any( target_os = "linux", @@ -586,10 +586,10 @@ pub fn fallocate( target_env = "freebsd" ))] mod posix_fadvise { - use errno::Errno; + use crate::errno::Errno; use libc; use std::os::unix::io::RawFd; - use Result; + use crate::Result; libc_enum! { #[repr(i32)] diff --git a/src/features.rs b/src/features.rs index 827eecacb5..c3a53fbfd2 100644 --- a/src/features.rs +++ b/src/features.rs @@ -3,7 +3,7 @@ pub use self::os::*; #[cfg(any(target_os = "linux", target_os = "android"))] mod os { - use sys::utsname::uname; + use crate::sys::utsname::uname; // Features: // * atomic cloexec on socket: 2.6.27 diff --git a/src/ifaddrs.rs b/src/ifaddrs.rs index 2c226cb438..ed6328f3ef 100644 --- a/src/ifaddrs.rs +++ b/src/ifaddrs.rs @@ -3,16 +3,15 @@ //! Uses the Linux and/or BSD specific function `getifaddrs` to query the list //! of interfaces and their associated addresses. +use cfg_if::cfg_if; use std::ffi; use std::iter::Iterator; use std::mem; use std::option::Option; -use libc; - -use {Result, Errno}; -use sys::socket::SockAddr; -use net::if_::*; +use crate::{Result, Errno}; +use crate::sys::socket::SockAddr; +use crate::net::if_::*; /// Describes a single address for an interface as returned by `getifaddrs`. #[derive(Clone, Debug, Eq, Hash, PartialEq)] diff --git a/src/kmod.rs b/src/kmod.rs index e853261b14..8789cb69f4 100644 --- a/src/kmod.rs +++ b/src/kmod.rs @@ -6,8 +6,8 @@ use libc; use std::ffi::CStr; use std::os::unix::io::AsRawFd; -use errno::Errno; -use Result; +use crate::errno::Errno; +use crate::Result; /// Loads a kernel module from a buffer. /// diff --git a/src/lib.rs b/src/lib.rs index 5e2db4f722..bb2db87342 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,14 +15,8 @@ #![deny(missing_copy_implementations)] #![deny(missing_debug_implementations)] -// External crates -#[macro_use] -extern crate bitflags; -#[macro_use] -extern crate cfg_if; - // Re-exported external crates -pub extern crate libc; +pub use libc; // Private internal modules #[macro_use] mod macros; diff --git a/src/macros.rs b/src/macros.rs index 1d298e6d4e..8b08b7d910 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -48,7 +48,7 @@ macro_rules! libc_bitflags { )+ } ) => { - bitflags! { + ::bitflags::bitflags! { $(#[$outer])* pub struct $BitFlags: $T { $( diff --git a/src/mount.rs b/src/mount.rs index b889911305..2c54761e2b 100644 --- a/src/mount.rs +++ b/src/mount.rs @@ -1,6 +1,6 @@ use libc::{self, c_ulong, c_int}; -use {Result, NixPath}; -use errno::Errno; +use crate::{Result, NixPath}; +use crate::errno::Errno; libc_bitflags!( pub struct MsFlags: c_ulong { diff --git a/src/mqueue.rs b/src/mqueue.rs index 331bac9b3e..122705a5b9 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -2,12 +2,12 @@ //! //! [Further reading and details on the C API](http://man7.org/linux/man-pages/man7/mq_overview.7.html) -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; use libc::{self, c_char, c_long, mqd_t, size_t}; use std::ffi::CString; -use sys::stat::Mode; +use crate::sys::stat::Mode; use std::mem; libc_bitflags!{ diff --git a/src/net/if_.rs b/src/net/if_.rs index 58d677ae34..96364884e3 100644 --- a/src/net/if_.rs +++ b/src/net/if_.rs @@ -3,9 +3,8 @@ //! Uses Linux and/or POSIX functions to resolve interface names like "eth0" //! or "socan1" into device numbers. -use libc; use libc::c_uint; -use {Result, Error, NixPath}; +use crate::{Result, Error, NixPath}; /// Resolve an interface into a interface number. pub fn if_nametoindex(name: &P) -> Result { diff --git a/src/poll.rs b/src/poll.rs index 80784a543b..e276090eb2 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -1,13 +1,12 @@ //! Wait for events to trigger on specific file descriptors #[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))] -use sys::time::TimeSpec; +use crate::sys::time::TimeSpec; #[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))] -use sys::signal::SigSet; +use crate::sys::signal::SigSet; use std::os::unix::io::RawFd; -use libc; -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; /// This is a wrapper around `libc::pollfd`. /// diff --git a/src/pty.rs b/src/pty.rs index e6c7953a1a..3a6a9232f4 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -1,7 +1,5 @@ //! Create master and slave virtual pseudo-terminals (PTYs) -use libc; - pub use libc::pid_t as SessionId; pub use libc::winsize as Winsize; @@ -10,10 +8,10 @@ use std::io; use std::mem; use std::os::unix::prelude::*; -use sys::termios::Termios; -use unistd::ForkResult; -use {Result, Error, fcntl}; -use errno::Errno; +use crate::sys::termios::Termios; +use crate::unistd::{self, ForkResult, Pid}; +use crate::{Result, Error, fcntl}; +use crate::errno::Errno; /// Representation of a master/slave pty pair /// @@ -71,7 +69,7 @@ impl Drop for PtyMaster { // invalid file descriptor. That frequently indicates a double-close // condition, which can cause confusing errors for future I/O // operations. - let e = ::unistd::close(self.0); + let e = unistd::close(self.0); if e == Err(Error::Sys(Errno::EBADF)) { panic!("Closing an invalid file descriptor!"); }; @@ -80,13 +78,13 @@ impl Drop for PtyMaster { impl io::Read for PtyMaster { fn read(&mut self, buf: &mut [u8]) -> io::Result { - ::unistd::read(self.0, buf).map_err(|e| e.as_errno().unwrap().into()) + unistd::read(self.0, buf).map_err(|e| e.as_errno().unwrap().into()) } } impl io::Write for PtyMaster { fn write(&mut self, buf: &[u8]) -> io::Result { - ::unistd::write(self.0, buf).map_err(|e| e.as_errno().unwrap().into()) + unistd::write(self.0, buf).map_err(|e| e.as_errno().unwrap().into()) } fn flush(&mut self) -> io::Result<()> { Ok(()) @@ -309,8 +307,6 @@ pub fn forkpty<'a, 'b, T: Into>, U: Into termios: U, ) -> Result { use std::ptr; - use unistd::Pid; - use unistd::ForkResult::*; let mut master = mem::MaybeUninit::::uninit(); @@ -332,8 +328,8 @@ pub fn forkpty<'a, 'b, T: Into>, U: Into }; let fork_result = Errno::result(res).map(|res| match res { - 0 => Child, - res => Parent { child: Pid::from_raw(res) }, + 0 => ForkResult::Child, + res => ForkResult::Parent { child: Pid::from_raw(res) }, })?; unsafe { diff --git a/src/sched.rs b/src/sched.rs index 7675dbc279..064deb8c0c 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -1,18 +1,17 @@ -use libc; -use {Errno, Result}; +use crate::{Errno, Result}; #[cfg(any(target_os = "android", target_os = "linux"))] pub use self::sched_linux_like::*; #[cfg(any(target_os = "android", target_os = "linux"))] mod sched_linux_like { - use errno::Errno; + use crate::errno::Errno; use libc::{self, c_int, c_void}; use std::mem; use std::option::Option; use std::os::unix::io::RawFd; - use unistd::Pid; - use {Error, Result}; + use crate::unistd::Pid; + use crate::{Error, Result}; // For some functions taking with a parameter of type CloneFlags, // only a subset of these flags have an effect. diff --git a/src/sys/aio.rs b/src/sys/aio.rs index c912fc839f..1afdb35866 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -21,20 +21,19 @@ //! [`aio_cancel_all`](fn.aio_cancel_all.html), though the operating system may //! not support this for all filesystems and devices. -use {Error, Result}; -use errno::Errno; +use crate::{Error, Result}; +use crate::errno::Errno; use std::os::unix::io::RawFd; use libc::{c_void, off_t, size_t}; -use libc; use std::borrow::{Borrow, BorrowMut}; use std::fmt; use std::fmt::Debug; use std::marker::PhantomData; use std::mem; use std::ptr::{null, null_mut}; -use sys::signal::*; +use crate::sys::signal::*; use std::thread; -use sys::time::TimeSpec; +use crate::sys::time::TimeSpec; libc_enum! { /// Mode for `AioCb::fsync`. Controls whether only data or both data and @@ -226,8 +225,6 @@ impl<'a> AioCb<'a> { /// [`fsync`](#method.fsync) operation. /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -287,8 +284,6 @@ impl<'a> AioCb<'a> { /// Create an `AioCb` from a mutable slice and read into it. /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -363,8 +358,6 @@ impl<'a> AioCb<'a> { /// Create an `AioCb` from a Vector and use it for writing /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -394,9 +387,6 @@ impl<'a> AioCb<'a> { /// Create an `AioCb` from a `Bytes` object /// /// ``` - /// # extern crate bytes; - /// # extern crate tempfile; - /// # extern crate nix; /// # use bytes::Bytes; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; @@ -419,9 +409,6 @@ impl<'a> AioCb<'a> { /// using an un`Box`ed `Bytes` object. /// /// ``` - /// # extern crate bytes; - /// # extern crate tempfile; - /// # extern crate nix; /// # use bytes::Bytes; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; @@ -480,8 +467,6 @@ impl<'a> AioCb<'a> { /// Create an `AioCb` from a Vector and use it for reading /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -642,8 +627,6 @@ impl<'a> AioCb<'a> { /// Construct an `AioCb` from a slice and use it for writing. /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -726,8 +709,6 @@ impl<'a> AioCb<'a> { /// result. /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -781,8 +762,6 @@ impl<'a> AioCb<'a> { /// is an alternative to `aio_suspend`, used by most of the other examples. /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -925,8 +904,6 @@ impl<'a> AioCb<'a> { /// descriptor. /// /// ``` -/// # extern crate tempfile; -/// # extern crate nix; /// # use nix::errno::Errno; /// # use nix::Error; /// # use nix::sys::aio::*; @@ -979,8 +956,6 @@ pub fn aio_cancel_all(fd: RawFd) -> Result { /// Use `aio_suspend` to block until an aio operation completes. /// /// ``` -/// # extern crate tempfile; -/// # extern crate nix; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; /// # use std::os::unix::io::AsRawFd; @@ -1087,8 +1062,6 @@ impl<'a> LioCb<'a> { /// [`AioCb::error`] to poll. /// /// ``` - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; /// # use std::os::unix::io::AsRawFd; @@ -1144,8 +1117,6 @@ impl<'a> LioCb<'a> { /// /// # Examples /// ```no_run - /// # extern crate tempfile; - /// # extern crate nix; /// # use nix::Error; /// # use nix::errno::Errno; /// # use nix::sys::aio::*; diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index 074a8451db..2437bbe2dd 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -1,10 +1,10 @@ -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; use libc::{self, c_int}; use std::os::unix::io::RawFd; use std::ptr; use std::mem; -use ::Error; +use crate::Error; libc_bitflags!( pub struct EpollFlags: c_int { diff --git a/src/sys/event.rs b/src/sys/event.rs index 7af5ae2b15..1da0f8fef1 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -1,12 +1,11 @@ /* TOOD: Implement for other kqueue based systems */ -use {Errno, Result}; +use crate::{Errno, Result}; #[cfg(not(target_os = "netbsd"))] use libc::{timespec, time_t, c_int, c_long, intptr_t, uintptr_t}; #[cfg(target_os = "netbsd")] use libc::{timespec, time_t, c_long, intptr_t, uintptr_t, size_t}; -use libc; use std::os::unix::io::RawFd; use std::ptr; use std::mem; diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index c5a54e46a1..baaaa89ddd 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -1,7 +1,7 @@ use libc; use std::os::unix::io::RawFd; -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; libc_bitflags! { pub struct EfdFlags: libc::c_int { diff --git a/src/sys/inotify.rs b/src/sys/inotify.rs index e6c2cf64d2..078015b6fd 100644 --- a/src/sys/inotify.rs +++ b/src/sys/inotify.rs @@ -23,7 +23,6 @@ //! } //! ``` -use libc; use libc::{ c_char, c_int, @@ -32,10 +31,10 @@ use std::ffi::{OsString,OsStr,CStr}; use std::os::unix::ffi::OsStrExt; use std::mem::size_of; use std::os::unix::io::{RawFd,AsRawFd,FromRawFd}; -use unistd::read; -use Result; -use NixPath; -use errno::Errno; +use crate::unistd::read; +use crate::Result; +use crate::NixPath; +use crate::errno::Errno; libc_bitflags! { /// Configuration options for [`inotify_add_watch`](fn.inotify_add_watch.html). diff --git a/src/sys/ioctl/bsd.rs b/src/sys/ioctl/bsd.rs index 20c804485f..f39c0eb688 100644 --- a/src/sys/ioctl/bsd.rs +++ b/src/sys/ioctl/bsd.rs @@ -6,7 +6,7 @@ pub type ioctl_num_type = ::libc::c_ulong; pub type ioctl_param_type = ::libc::c_int; mod consts { - use ::sys::ioctl::ioctl_num_type; + use crate::sys::ioctl::ioctl_num_type; #[doc(hidden)] pub const VOID: ioctl_num_type = 0x2000_0000; #[doc(hidden)] diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs index 3bcdd26661..60f169dbcb 100644 --- a/src/sys/ioctl/mod.rs +++ b/src/sys/ioctl/mod.rs @@ -221,6 +221,8 @@ //! //! # fn main() {} //! ``` +use cfg_if::cfg_if; + #[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))] #[macro_use] mod linux; @@ -317,7 +319,6 @@ macro_rules! ioctl_none { /// /// ```no_run /// # #[macro_use] extern crate nix; -/// # extern crate libc; /// # use libc::TIOCNXCL; /// # use std::fs::File; /// # use std::os::unix::io::AsRawFd; @@ -396,7 +397,6 @@ macro_rules! ioctl_read { /// # Example /// /// ``` -/// # extern crate libc; /// # #[macro_use] extern crate nix; /// # #[cfg(any(target_os = "android", target_os = "linux"))] /// ioctl_read_bad!(tcgets, libc::TCGETS, libc::termios); @@ -470,7 +470,6 @@ macro_rules! ioctl_write_ptr { /// # Example /// /// ``` -/// # extern crate libc; /// # #[macro_use] extern crate nix; /// # #[cfg(any(target_os = "android", target_os = "linux"))] /// ioctl_write_ptr_bad!(tcsets, libc::TCSETS, libc::termios); @@ -590,7 +589,6 @@ cfg_if!{ /// # Examples /// /// ``` -/// # extern crate libc; /// # #[macro_use] extern crate nix; /// # #[cfg(any(target_os = "android", target_os = "linux"))] /// ioctl_write_int_bad!(tcsbrk, libc::TCSBRK); diff --git a/src/sys/memfd.rs b/src/sys/memfd.rs index 9672429b31..51b7e6b188 100644 --- a/src/sys/memfd.rs +++ b/src/sys/memfd.rs @@ -1,7 +1,7 @@ use libc; use std::os::unix::io::RawFd; -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; use std::ffi::CStr; libc_bitflags!( diff --git a/src/sys/mman.rs b/src/sys/mman.rs index dfa46264c9..5a5dd89e06 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -1,12 +1,12 @@ -use {Error, Result}; +use crate::{Error, Result}; #[cfg(not(target_os = "android"))] -use NixPath; -use errno::Errno; +use crate::NixPath; +use crate::errno::Errno; #[cfg(not(target_os = "android"))] -use fcntl::OFlag; +use crate::fcntl::OFlag; use libc::{self, c_int, c_void, size_t, off_t}; #[cfg(not(target_os = "android"))] -use sys::stat::Mode; +use crate::sys::stat::Mode; use std::os::unix::io::RawFd; libc_bitflags!{ diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs index 18265d316d..e85afc7611 100644 --- a/src/sys/ptrace/bsd.rs +++ b/src/sys/ptrace/bsd.rs @@ -1,9 +1,10 @@ -use errno::Errno; +use cfg_if::cfg_if; +use crate::errno::Errno; use libc::{self, c_int}; use std::ptr; -use sys::signal::Signal; -use unistd::Pid; -use Result; +use crate::sys::signal::Signal; +use crate::unistd::Pid; +use crate::Result; pub type RequestType = c_int; @@ -128,7 +129,6 @@ pub fn kill(pid: Pid) -> Result<()> { /// /// # Example /// ```rust -/// extern crate nix; /// use nix::sys::ptrace::step; /// use nix::unistd::Pid; /// use nix::sys::signal::Signal; diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 6c9559e2ad..49a45d6460 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -1,11 +1,12 @@ //! For detailed description of the ptrace requests, consult `man ptrace`. +use cfg_if::cfg_if; use std::{mem, ptr}; -use {Error, Result}; -use errno::Errno; +use crate::{Error, Result}; +use crate::errno::Errno; use libc::{self, c_void, c_long, siginfo_t}; -use ::unistd::Pid; -use sys::signal::Signal; +use crate::unistd::Pid; +use crate::sys::signal::Signal; pub type AddressType = *mut ::libc::c_void; @@ -391,7 +392,6 @@ pub fn kill(pid: Pid) -> Result<()> { /// /// # Example /// ```rust -/// extern crate nix; /// use nix::sys::ptrace::step; /// use nix::unistd::Pid; /// use nix::sys::signal::Signal; diff --git a/src/sys/quota.rs b/src/sys/quota.rs index db97b0e765..1199d5f967 100644 --- a/src/sys/quota.rs +++ b/src/sys/quota.rs @@ -15,8 +15,8 @@ use std::default::Default; use std::{mem, ptr}; use libc::{self, c_int, c_char}; -use {Result, NixPath}; -use errno::Errno; +use crate::{Result, NixPath}; +use crate::errno::Errno; struct QuotaCmd(QuotaSubCmd, QuotaType); diff --git a/src/sys/reboot.rs b/src/sys/reboot.rs index d18b44d6ad..e319130698 100644 --- a/src/sys/reboot.rs +++ b/src/sys/reboot.rs @@ -1,7 +1,7 @@ //! Reboot/shutdown or enable/disable Ctrl-Alt-Delete. -use {Error, Result}; -use errno::Errno; +use crate::{Error, Result}; +use crate::errno::Errno; use libc; use std::convert::Infallible; use std::mem::drop; diff --git a/src/sys/select.rs b/src/sys/select.rs index a46985bc4c..a576c7e492 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -4,10 +4,10 @@ use std::ops::Range; use std::os::unix::io::RawFd; use std::ptr::{null, null_mut}; use libc::{self, c_int}; -use Result; -use errno::Errno; -use sys::signal::SigSet; -use sys::time::{TimeSpec, TimeVal}; +use crate::Result; +use crate::errno::Errno; +use crate::sys::signal::SigSet; +use crate::sys::time::{TimeSpec, TimeVal}; pub use libc::FD_SETSIZE; @@ -49,7 +49,6 @@ impl FdSet { /// # Example /// /// ``` - /// # extern crate nix; /// # use nix::sys::select::FdSet; /// # fn main() { /// let mut set = FdSet::new(); @@ -73,7 +72,6 @@ impl FdSet { /// # Examples /// /// ``` - /// # extern crate nix; /// # use nix::sys::select::FdSet; /// # use std::os::unix::io::RawFd; /// let mut set = FdSet::new(); @@ -275,8 +273,8 @@ where mod tests { use super::*; use std::os::unix::io::RawFd; - use sys::time::{TimeVal, TimeValLike}; - use unistd::{write, pipe}; + use crate::sys::time::{TimeVal, TimeValLike}; + use crate::unistd::{write, pipe}; #[test] fn fdset_insert() { diff --git a/src/sys/sendfile.rs b/src/sys/sendfile.rs index 1618558a10..84fe2a919e 100644 --- a/src/sys/sendfile.rs +++ b/src/sys/sendfile.rs @@ -1,10 +1,11 @@ +use cfg_if::cfg_if; use std::os::unix::io::RawFd; use std::ptr; use libc::{self, off_t}; -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; /// Copy up to `count` bytes to `out_fd` from `in_fd` starting at `offset`. /// @@ -36,7 +37,7 @@ cfg_if! { if #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] { - use sys::uio::IoVec; + use crate::sys::uio::IoVec; #[derive(Clone, Debug, Eq, Hash, PartialEq)] struct SendfileHeaderTrailer<'a>( diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 2b36c957ed..710e65f53b 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -3,9 +3,9 @@ ///! Operating system signals. -use libc; -use {Error, Result}; -use errno::Errno; +use crate::{Error, Result}; +use crate::errno::Errno; +use crate::unistd::Pid; use std::convert::TryFrom; use std::mem; use std::fmt; @@ -623,8 +623,6 @@ pub unsafe fn sigaction(signal: Signal, sigaction: &SigAction) -> Result, oldset: Option<&mut Si Errno::result(res).map(drop) } -pub fn kill>>(pid: ::unistd::Pid, signal: T) -> Result<()> { +pub fn kill>>(pid: Pid, signal: T) -> Result<()> { let res = unsafe { libc::kill(pid.into(), match signal.into() { Some(s) => s as libc::c_int, @@ -751,7 +749,7 @@ pub fn kill>>(pid: ::unistd::Pid, signal: T) -> Result<() /// If `pgrp` less then or equal 1, the behavior is platform-specific. /// If `signal` is `None`, `killpg` will only preform error checking and won't /// send any signal. -pub fn killpg>>(pgrp: ::unistd::Pid, signal: T) -> Result<()> { +pub fn killpg>>(pgrp: Pid, signal: T) -> Result<()> { let res = unsafe { libc::killpg(pgrp.into(), match signal.into() { Some(s) => s as libc::c_int, @@ -802,7 +800,6 @@ pub enum SigevNotify { #[cfg(not(any(target_os = "openbsd", target_os = "redox")))] mod sigevent { - use libc; use std::mem; use std::ptr; use super::SigevNotify; @@ -1019,7 +1016,6 @@ mod tests { #[test] #[cfg(not(target_os = "redox"))] fn test_sigaction() { - use libc; thread::spawn(|| { extern fn test_sigaction_handler(_: libc::c_int) {} extern fn test_sigaction_action(_: libc::c_int, diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs index 6482eeb330..e3ded1f7ae 100644 --- a/src/sys/signalfd.rs +++ b/src/sys/signalfd.rs @@ -16,10 +16,10 @@ //! Please note that signal discarding is not specific to `signalfd`, but also happens with regular //! signal handlers. use libc; -use unistd; -use {Error, Result}; -use errno::Errno; -pub use sys::signal::{self, SigSet}; +use crate::unistd; +use crate::{Error, Result}; +use crate::errno::Errno; +pub use crate::sys::signal::{self, SigSet}; pub use libc::signalfd_siginfo as siginfo; use std::os::unix::io::{RawFd, AsRawFd}; diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 27883254cd..cdfa704deb 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1,20 +1,19 @@ use super::sa_family_t; -use {Error, Result, NixPath}; -use errno::Errno; -use libc; +use crate::{Error, Result, NixPath}; +use crate::errno::Errno; use std::{fmt, mem, net, ptr, slice}; use std::ffi::OsStr; use std::hash::{Hash, Hasher}; use std::path::Path; use std::os::unix::ffi::OsStrExt; #[cfg(any(target_os = "android", target_os = "linux"))] -use ::sys::socket::addr::netlink::NetlinkAddr; +use crate::sys::socket::addr::netlink::NetlinkAddr; #[cfg(any(target_os = "android", target_os = "linux"))] -use ::sys::socket::addr::alg::AlgAddr; +use crate::sys::socket::addr::alg::AlgAddr; #[cfg(any(target_os = "ios", target_os = "macos"))] use std::os::unix::io::RawFd; #[cfg(any(target_os = "ios", target_os = "macos"))] -use ::sys::socket::addr::sys_control::SysControlAddr; +use crate::sys::socket::addr::sys_control::SysControlAddr; #[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", @@ -851,7 +850,7 @@ impl fmt::Display for SockAddr { #[cfg(any(target_os = "android", target_os = "linux"))] pub mod netlink { - use ::sys::socket::addr::AddressFamily; + use crate::sys::socket::addr::AddressFamily; use libc::{sa_family_t, sockaddr_nl}; use std::{fmt, mem}; @@ -949,11 +948,11 @@ pub mod alg { #[cfg(any(target_os = "ios", target_os = "macos"))] pub mod sys_control { - use ::sys::socket::addr::AddressFamily; + use crate::sys::socket::addr::AddressFamily; use libc::{self, c_uchar}; use std::{fmt, mem}; use std::os::unix::io::RawFd; - use {Errno, Error, Result}; + use crate::{Errno, Error, Result}; // FIXME: Move type into `libc` #[repr(C)] @@ -1021,7 +1020,7 @@ pub mod sys_control { #[cfg(any(target_os = "android", target_os = "linux"))] mod datalink { - use super::{libc, fmt, AddressFamily}; + use super::{fmt, AddressFamily}; /// Hardware Address #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] @@ -1093,7 +1092,7 @@ mod datalink { target_os = "netbsd", target_os = "openbsd"))] mod datalink { - use super::{libc, fmt, AddressFamily}; + use super::{fmt, AddressFamily}; /// Hardware Address #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] @@ -1180,7 +1179,7 @@ mod datalink { #[cfg(target_os = "linux")] pub mod vsock { - use ::sys::socket::addr::AddressFamily; + use crate::sys::socket::addr::AddressFamily; use libc::{sa_family_t, sockaddr_vm}; use std::{fmt, mem}; use std::hash::{Hash, Hasher}; diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 52768c9351..28d6132acc 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1,14 +1,14 @@ //! Socket interface functions //! //! [Further reading](http://man7.org/linux/man-pages/man7/socket.7.html) -use {Error, Result}; -use errno::Errno; +use cfg_if::cfg_if; +use crate::{Error, Result, errno::Errno}; use libc::{self, c_void, c_int, iovec, socklen_t, size_t, CMSG_FIRSTHDR, CMSG_NXTHDR, CMSG_DATA, CMSG_LEN}; use std::{mem, ptr, slice}; use std::os::unix::io::RawFd; -use sys::time::TimeVal; -use sys::uio::IoVec; +use crate::sys::time::TimeVal; +use crate::sys::uio::IoVec; mod addr; pub mod sockopt; @@ -30,11 +30,11 @@ pub use self::addr::{ LinkAddr, }; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use ::sys::socket::addr::netlink::NetlinkAddr; +pub use crate::sys::socket::addr::netlink::NetlinkAddr; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use sys::socket::addr::alg::AlgAddr; +pub use crate::sys::socket::addr::alg::AlgAddr; #[cfg(target_os = "linux")] -pub use sys::socket::addr::vsock::VsockAddr; +pub use crate::sys::socket::addr::vsock::VsockAddr; pub use libc::{ cmsghdr, diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index fa19fb76cd..cbdf6691c1 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -1,7 +1,8 @@ +use cfg_if::cfg_if; use super::{GetSockOpt, SetSockOpt}; -use Result; -use errno::Errno; -use sys::time::TimeVal; +use crate::Result; +use crate::errno::Errno; +use crate::sys::time::TimeVal; use libc::{self, c_int, c_void, socklen_t}; use std::mem::{ self, @@ -650,7 +651,7 @@ mod test { #[test] fn is_socket_type_unix() { use super::super::*; - use ::unistd::close; + use crate::unistd::close; let (a, b) = socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::empty()).unwrap(); let a_type = getsockopt(a, super::SockType).unwrap(); @@ -662,7 +663,7 @@ mod test { #[test] fn is_socket_type_dgram() { use super::super::*; - use ::unistd::close; + use crate::unistd::close; let s = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), None).unwrap(); let s_type = getsockopt(s, super::SockType).unwrap(); @@ -676,7 +677,7 @@ mod test { #[test] fn can_get_listen_on_tcp_socket() { use super::super::*; - use ::unistd::close; + use crate::unistd::close; let s = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), None).unwrap(); let s_listening = getsockopt(s, super::AcceptConn).unwrap(); diff --git a/src/sys/stat.rs b/src/sys/stat.rs index f8fae4ee64..c3915b095b 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -1,14 +1,12 @@ pub use libc::{dev_t, mode_t}; pub use libc::stat as FileStat; -use {Result, NixPath}; -use errno::Errno; +use crate::{Result, NixPath, errno::Errno}; #[cfg(not(target_os = "redox"))] -use fcntl::{AtFlags, at_rawfd}; -use libc; +use crate::fcntl::{AtFlags, at_rawfd}; use std::mem; use std::os::unix::io::RawFd; -use sys::time::{TimeSpec, TimeVal}; +use crate::sys::time::{TimeSpec, TimeVal}; libc_bitflags!( pub struct SFlag: mode_t { diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs index 8e421167dc..3d46be9cad 100644 --- a/src/sys/statfs.rs +++ b/src/sys/statfs.rs @@ -4,10 +4,7 @@ use std::os::unix::io::AsRawFd; #[cfg(not(any(target_os = "linux", target_os = "android")))] use std::ffi::CStr; -use libc; - -use {NixPath, Result}; -use errno::Errno; +use crate::{NixPath, Result, errno::Errno}; #[cfg(target_os = "android")] pub type fsid_t = libc::__fsid_t; @@ -457,8 +454,8 @@ pub fn fstatfs(fd: &T) -> Result { mod test { use std::fs::File; - use sys::statfs::*; - use sys::statvfs::*; + use crate::sys::statfs::*; + use crate::sys::statvfs::*; use std::path::Path; #[test] diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs index 8e8d367cbf..9bea973492 100644 --- a/src/sys/statvfs.rs +++ b/src/sys/statvfs.rs @@ -7,8 +7,7 @@ use std::os::unix::io::AsRawFd; use libc::{self, c_ulong}; -use {Result, NixPath}; -use errno::Errno; +use crate::{Result, NixPath, errno::Errno}; #[cfg(not(target_os = "redox"))] libc_bitflags!( @@ -147,7 +146,7 @@ pub fn fstatvfs(fd: &T) -> Result { #[cfg(test)] mod test { use std::fs::File; - use sys::statvfs::*; + use crate::sys::statvfs::*; #[test] fn statvfs_call() { diff --git a/src/sys/sysinfo.rs b/src/sys/sysinfo.rs index 9807b444a6..f4b82798f7 100644 --- a/src/sys/sysinfo.rs +++ b/src/sys/sysinfo.rs @@ -2,8 +2,8 @@ use libc::{self, SI_LOAD_SHIFT}; use std::{cmp, mem}; use std::time::Duration; -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; /// System info structure returned by `sysinfo`. #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)] diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 0b9bfe9009..5af5a1588f 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -74,7 +74,6 @@ //! Additionally round-tripping baud rates is consistent across platforms: //! //! ```rust -//! # extern crate nix; //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetispeed, cfsetspeed, Termios}; //! # fn main() { //! # let mut t = unsafe { Termios::default_uninit() }; @@ -93,7 +92,6 @@ #![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")), doc = " ```rust")] -//! # extern crate nix; //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios}; //! # fn main() { //! # let mut t = unsafe { Termios::default_uninit() }; @@ -111,7 +109,6 @@ #![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")), doc = " ```rust,ignore")] -//! # extern crate nix; //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios}; //! # fn main() { //! # let mut t = unsafe { Termios::default_uninit() }; @@ -129,7 +126,6 @@ #![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")), doc = " ```rust,ignore")] -//! # extern crate nix; //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfsetspeed, Termios}; //! # fn main() { //! # let mut t = unsafe { Termios::default_uninit() }; @@ -148,7 +144,6 @@ #![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")), doc = " ```rust,ignore")] -//! # extern crate nix; //! # use nix::sys::termios::{cfsetispeed, cfsetospeed, cfsetspeed, Termios}; //! # fn main() { //! # let mut t = unsafe { Termios::default_uninit() }; @@ -157,15 +152,16 @@ //! cfsetspeed(&mut t, 9600u32); //! # } //! ``` -use {Error, Result}; -use errno::Errno; +use cfg_if::cfg_if; +use crate::{Error, Result}; +use crate::errno::Errno; use libc::{self, c_int, tcflag_t}; use std::cell::{Ref, RefCell}; use std::convert::{From, TryFrom}; use std::mem; use std::os::unix::io::RawFd; -use ::unistd::Pid; +use crate::unistd::Pid; /// Stores settings for the termios API /// @@ -193,8 +189,6 @@ impl Termios { /// This can be used for interfacing with other FFI functions like: /// /// ```rust - /// # extern crate libc; - /// # extern crate nix; /// # fn main() { /// # use nix::sys::termios::Termios; /// # let mut termios = unsafe { Termios::default_uninit() }; diff --git a/src/sys/uio.rs b/src/sys/uio.rs index 7dfeff77e0..65334227b4 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -1,8 +1,8 @@ // Silence invalid warnings due to rust-lang/rust#16719 #![allow(improper_ctypes)] -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; use libc::{self, c_int, c_void, size_t, off_t}; use std::marker::PhantomData; use std::os::unix::io::RawFd; @@ -117,7 +117,11 @@ pub struct RemoteIoVec { /// [`IoVec`]: struct.IoVec.html /// [`RemoteIoVec`]: struct.RemoteIoVec.html #[cfg(target_os = "linux")] -pub fn process_vm_writev(pid: ::unistd::Pid, local_iov: &[IoVec<&[u8]>], remote_iov: &[RemoteIoVec]) -> Result { +pub fn process_vm_writev( + pid: crate::unistd::Pid, + local_iov: &[IoVec<&[u8]>], + remote_iov: &[RemoteIoVec]) -> Result +{ let res = unsafe { libc::process_vm_writev(pid.into(), local_iov.as_ptr() as *const libc::iovec, local_iov.len() as libc::c_ulong, @@ -148,7 +152,11 @@ pub fn process_vm_writev(pid: ::unistd::Pid, local_iov: &[IoVec<&[u8]>], remote_ /// [`IoVec`]: struct.IoVec.html /// [`RemoteIoVec`]: struct.RemoteIoVec.html #[cfg(any(target_os = "linux"))] -pub fn process_vm_readv(pid: ::unistd::Pid, local_iov: &[IoVec<&mut [u8]>], remote_iov: &[RemoteIoVec]) -> Result { +pub fn process_vm_readv( + pid: crate::unistd::Pid, + local_iov: &[IoVec<&mut [u8]>], + remote_iov: &[RemoteIoVec]) -> Result +{ let res = unsafe { libc::process_vm_readv(pid.into(), local_iov.as_ptr() as *const libc::iovec, local_iov.len() as libc::c_ulong, diff --git a/src/sys/wait.rs b/src/sys/wait.rs index 252ef28d0f..9825102ceb 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -1,10 +1,10 @@ +use cfg_if::cfg_if; use libc::{self, c_int}; -use Result; -use errno::Errno; +use crate::Result; +use crate::errno::Errno; +use crate::unistd::Pid; +use crate::sys::signal::Signal; use std::convert::TryFrom; -use unistd::Pid; - -use sys::signal::Signal; libc_bitflags!( pub struct WaitPidFlag: c_int { diff --git a/src/ucontext.rs b/src/ucontext.rs index 1bcfdd9b7a..9c1e8d2ace 100644 --- a/src/ucontext.rs +++ b/src/ucontext.rs @@ -1,10 +1,10 @@ use libc; #[cfg(not(target_env = "musl"))] -use Result; +use crate::Result; #[cfg(not(target_env = "musl"))] -use errno::Errno; +use crate::errno::Errno; use std::mem; -use sys::signal::SigSet; +use crate::sys::signal::SigSet; #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct UContext { diff --git a/src/unistd.rs b/src/unistd.rs index 4e0bf7b154..8ff71e0532 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1,11 +1,13 @@ //! Safe wrappers around functions found in libc "unistd.h" header -use errno::{self, Errno}; -use {Error, Result, NixPath}; #[cfg(not(target_os = "redox"))] -use fcntl::{AtFlags, at_rawfd}; -use fcntl::{FdFlag, OFlag, fcntl}; -use fcntl::FcntlArg::F_SETFD; +use cfg_if::cfg_if; +use crate::errno::{self, Errno}; +use crate::{Error, Result, NixPath}; +#[cfg(not(target_os = "redox"))] +use crate::fcntl::{AtFlags, at_rawfd}; +use crate::fcntl::{FdFlag, OFlag, fcntl}; +use crate::fcntl::FcntlArg::F_SETFD; use libc::{self, c_char, c_void, c_int, c_long, c_uint, size_t, pid_t, off_t, uid_t, gid_t, mode_t, PATH_MAX}; use std::{fmt, mem, ptr}; @@ -18,7 +20,7 @@ use std::os::unix::ffi::OsStringExt; use std::os::unix::ffi::OsStrExt; use std::os::unix::io::RawFd; use std::path::PathBuf; -use sys::stat::Mode; +use crate::sys::stat::Mode; #[cfg(any(target_os = "android", target_os = "linux"))] pub use self::pivot_root::*; @@ -443,9 +445,6 @@ pub fn fchdir(dirfd: RawFd) -> Result<()> { /// # Example /// /// ```rust -/// extern crate tempfile; -/// extern crate nix; -/// /// use nix::unistd; /// use nix::sys::stat; /// use tempfile::tempdir; @@ -486,9 +485,6 @@ pub fn mkdir(path: &P, mode: Mode) -> Result<()> { /// # Example /// /// ```rust -/// extern crate tempfile; -/// extern crate nix; -/// /// use nix::unistd; /// use nix::sys::stat; /// use tempfile::tempdir; @@ -588,8 +584,6 @@ fn reserve_double_buffer_size(buf: &mut Vec, limit: usize) -> Result<()> { /// # Example /// /// ```rust -/// extern crate nix; -/// /// use nix::unistd; /// /// fn main() { @@ -953,9 +947,6 @@ pub fn gethostname(buffer: &mut [u8]) -> Result<&CStr> { /// # Examples /// /// ```no_run -/// extern crate tempfile; -/// extern crate nix; -/// /// use std::os::unix::io::AsRawFd; /// use nix::unistd::close; /// @@ -966,9 +957,6 @@ pub fn gethostname(buffer: &mut [u8]) -> Result<&CStr> { /// ``` /// /// ```rust -/// extern crate tempfile; -/// extern crate nix; -/// /// use std::os::unix::io::IntoRawFd; /// use nix::unistd::close; /// @@ -1123,7 +1111,7 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> { #[cfg(any(target_os = "ios", target_os = "macos"))] fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> { - use fcntl::FcntlArg::F_SETFL; + use crate::fcntl::FcntlArg::F_SETFL; let mut res = Ok(0); @@ -1720,8 +1708,6 @@ pub mod alarm { //! //! See also [alarm(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/alarm.html). - use libc; - /// Schedule an alarm signal. /// /// This will cause the system to generate a `SIGALRM` signal for the @@ -1759,9 +1745,8 @@ pub fn sleep(seconds: c_uint) -> c_uint { #[cfg(not(target_os = "redox"))] pub mod acct { - use libc; - use {Result, NixPath}; - use errno::Errno; + use crate::{Result, NixPath}; + use crate::errno::Errno; use std::ptr; /// Enable process accounting @@ -2494,9 +2479,8 @@ pub fn sysconf(var: SysconfVar) -> Result> { #[cfg(any(target_os = "android", target_os = "linux"))] mod pivot_root { - use libc; - use {Result, NixPath}; - use errno::Errno; + use crate::{Result, NixPath}; + use crate::errno::Errno; pub fn pivot_root( new_root: &P1, put_old: &P2) -> Result<()> { @@ -2515,9 +2499,8 @@ mod pivot_root { #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux", target_os = "openbsd"))] mod setres { - use libc; - use Result; - use errno::Errno; + use crate::Result; + use crate::errno::Errno; use super::{Uid, Gid}; /// Sets the real, effective, and saved uid. diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index d03adc5e65..6b9bd91100 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -445,7 +445,7 @@ extern fn sigfunc(_: c_int) { #[test] #[cfg_attr(any(all(target_env = "musl", target_arch = "x86_64"), target_arch = "mips", target_arch = "mips64"), ignore)] fn test_write_sigev_signal() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); let sa = SigAction::new(SigHandler::Handler(sigfunc), SaFlags::SA_RESETHAND, SigSet::empty()); @@ -583,7 +583,7 @@ fn test_liocb_listio_nowait() { #[cfg(not(any(target_os = "ios", target_os = "macos")))] #[cfg_attr(any(target_arch = "mips", target_arch = "mips64", target_env = "musl"), ignore)] fn test_liocb_listio_signal() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); const INITIAL: &[u8] = b"abcdef123456"; const WBUF: &[u8] = b"CDEF"; let mut rbuf = vec![0; 4]; diff --git a/test/sys/test_aio_drop.rs b/test/sys/test_aio_drop.rs index 492da401ef..71a2183bc1 100644 --- a/test/sys/test_aio_drop.rs +++ b/test/sys/test_aio_drop.rs @@ -1,6 +1,3 @@ -extern crate nix; -extern crate tempfile; - // Test dropping an AioCb that hasn't yet finished. // This must happen in its own process, because on OSX this test seems to hose // the AIO subsystem and causes subsequent tests to fail diff --git a/test/sys/test_lio_listio_resubmit.rs b/test/sys/test_lio_listio_resubmit.rs index 19ee3facf8..0795370b8c 100644 --- a/test/sys/test_lio_listio_resubmit.rs +++ b/test/sys/test_lio_listio_resubmit.rs @@ -4,10 +4,6 @@ // we must disable the test here rather than in Cargo.toml #![cfg(target_os = "freebsd")] -extern crate nix; -extern crate sysctl; -extern crate tempfile; - use nix::Error; use nix::errno::*; use nix::libc::off_t; diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index cb2f04e9ed..05f407cc48 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -68,7 +68,7 @@ fn test_ptrace_cont() { require_capability!(CAP_SYS_PTRACE); - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // FIXME: qemu-user doesn't implement ptrace on all architectures // and retunrs ENOSYS in this case. @@ -128,7 +128,7 @@ fn test_ptrace_syscall() { use nix::unistd::getpid; use nix::unistd::ForkResult::*; - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); match fork().expect("Error: Fork Failed") { Child => { diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs index cf68700c5e..37951086c2 100644 --- a/test/sys/test_select.rs +++ b/test/sys/test_select.rs @@ -5,7 +5,7 @@ use nix::sys::time::{TimeSpec, TimeValLike}; #[test] pub fn test_pselect() { - let _mtx = ::SIGNAL_MTX + let _mtx = crate::SIGNAL_MTX .lock() .expect("Mutex got poisoned by another test"); diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs index 1c3a25f881..5e0b276225 100644 --- a/test/sys/test_signal.rs +++ b/test/sys/test_signal.rs @@ -19,7 +19,7 @@ fn test_killpg_none() { #[test] fn test_old_sigaction_flags() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); extern "C" fn handler(_: ::libc::c_int) {} let act = SigAction::new( @@ -41,7 +41,7 @@ fn test_sigprocmask_noop() { #[test] fn test_sigprocmask() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); // This needs to be a signal that rust doesn't use in the test harness. const SIGNAL: Signal = Signal::SIGCHLD; @@ -89,7 +89,7 @@ extern fn test_sigaction_action(_: libc::c_int, _: *mut libc::siginfo_t, _: *mut #[test] #[cfg(not(target_os = "redox"))] fn test_signal_sigaction() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + 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::UnsupportedOperation); @@ -97,7 +97,7 @@ fn test_signal_sigaction() { #[test] fn test_signal() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); unsafe { signal(Signal::SIGINT, SigHandler::SigIgn) }.unwrap(); raise(Signal::SIGINT).unwrap(); diff --git a/test/sys/test_signalfd.rs b/test/sys/test_signalfd.rs index 92759a486d..af04c22285 100644 --- a/test/sys/test_signalfd.rs +++ b/test/sys/test_signalfd.rs @@ -6,7 +6,7 @@ fn test_signalfd() { use nix::sys::signal::{self, raise, Signal, SigSet}; // Grab the mutex for altering signals so we don't interfere with other tests. - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); // Block the SIGUSR1 signal from automatic processing for this thread let mut mask = SigSet::empty(); diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs index a14b8ce1a2..40b47af4e1 100644 --- a/test/sys/test_termios.rs +++ b/test/sys/test_termios.rs @@ -19,7 +19,7 @@ fn write_all(f: RawFd, buf: &[u8]) { #[test] fn test_tcgetattr_pty() { // openpty uses ptname(3) internally - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); let pty = openpty(None, None).expect("openpty failed"); assert!(termios::tcgetattr(pty.master).is_ok()); @@ -46,7 +46,7 @@ fn test_tcgetattr_ebadf() { #[test] fn test_output_flags() { // openpty uses ptname(3) internally - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open one pty to get attributes for the second one let mut termios = { @@ -77,7 +77,7 @@ fn test_output_flags() { // Read from the slave verifying that the output has been properly transformed let mut buf = [0u8; 10]; - ::read_exact(pty.slave, &mut buf); + crate::read_exact(pty.slave, &mut buf); let transformed_string = "foofoofoo\n"; close(pty.master).unwrap(); close(pty.slave).unwrap(); @@ -88,7 +88,7 @@ fn test_output_flags() { #[test] fn test_local_flags() { // openpty uses ptname(3) internally - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open one pty to get attributes for the second one let mut termios = { diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index d0025b872d..236560f43a 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -205,7 +205,7 @@ fn test_process_vm_readv() { use nix::sys::wait::*; require_capability!(CAP_SYS_PTRACE); - let _ = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _ = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Pre-allocate memory in the child, since allocation isn't safe // post-fork (~= async-signal-safe) diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs index 6b0fb3217d..53b7c84ac8 100644 --- a/test/sys/test_wait.rs +++ b/test/sys/test_wait.rs @@ -8,7 +8,7 @@ use libc::_exit; #[test] #[cfg(not(target_os = "redox"))] fn test_wait_signal() { - let _ = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _ = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: The child only calls `pause` and/or `_exit`, which are async-signal-safe. match fork().expect("Error: Fork Failed") { @@ -25,7 +25,7 @@ fn test_wait_signal() { #[test] fn test_wait_exit() { - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: Child only calls `_exit`, which is async-signal-safe. match fork().expect("Error: Fork Failed") { @@ -46,7 +46,7 @@ fn test_waitstatus_from_raw() { #[test] fn test_waitstatus_pid() { - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); match fork().unwrap() { Child => unsafe { _exit(0) }, @@ -96,7 +96,7 @@ mod ptrace { #[test] fn test_wait_ptrace() { require_capability!(CAP_SYS_PTRACE); - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); match fork().expect("Error: Fork Failed") { Child => ptrace_child(), diff --git a/test/test.rs b/test/test.rs index 5319c1d899..ac842b1134 100644 --- a/test/test.rs +++ b/test/test.rs @@ -1,18 +1,9 @@ -extern crate bytes; -#[cfg(any(target_os = "android", target_os = "linux"))] -extern crate caps; #[macro_use] extern crate cfg_if; #[cfg_attr(not(target_os = "redox"), macro_use)] extern crate nix; #[macro_use] extern crate lazy_static; -extern crate libc; -extern crate rand; -#[cfg(target_os = "freebsd")] -extern crate sysctl; -extern crate tempfile; -extern crate semver; cfg_if! { if #[cfg(any(target_os = "android", target_os = "linux"))] { @@ -207,7 +198,7 @@ struct DirRestore<'a> { impl<'a> DirRestore<'a> { fn new() -> Self { - let guard = ::CWD_LOCK.write() + let guard = crate::CWD_LOCK.write() .expect("Lock got poisoned by another test"); DirRestore{ _g: guard, diff --git a/test/test_clearenv.rs b/test/test_clearenv.rs index f122f7c67f..28a7768049 100644 --- a/test/test_clearenv.rs +++ b/test/test_clearenv.rs @@ -1,5 +1,3 @@ -extern crate nix; - use std::env; #[test] diff --git a/test/test_dir.rs b/test/test_dir.rs index c42fbcd18a..c5f9c51735 100644 --- a/test/test_dir.rs +++ b/test/test_dir.rs @@ -1,11 +1,8 @@ -extern crate nix; -extern crate tempfile; - use nix::dir::{Dir, Type}; use nix::fcntl::OFlag; use nix::sys::stat::Mode; use std::fs::File; -use self::tempfile::tempdir; +use tempfile::tempdir; #[test] fn read() { diff --git a/test/test_kmod/mod.rs b/test/test_kmod/mod.rs index ad406357b0..e7472ab871 100644 --- a/test/test_kmod/mod.rs +++ b/test/test_kmod/mod.rs @@ -4,7 +4,7 @@ use std::process::Command; use tempfile::{tempdir, TempDir}; fn compile_kernel_module() -> (PathBuf, String, TempDir) { - let _m = ::FORK_MTX + let _m = crate::FORK_MTX .lock() .expect("Mutex got poisoned by another test"); @@ -41,8 +41,8 @@ use std::io::Read; #[test] fn test_finit_and_delete_module() { require_capability!(CAP_SYS_MODULE); - let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); - let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module(); @@ -59,8 +59,8 @@ fn test_finit_and_delete_module() { #[test] fn test_finit_and_delete_modul_with_params() { require_capability!(CAP_SYS_MODULE); - let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); - let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module(); @@ -80,8 +80,8 @@ fn test_finit_and_delete_modul_with_params() { #[test] fn test_init_and_delete_module() { require_capability!(CAP_SYS_MODULE); - let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); - let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module(); @@ -100,8 +100,8 @@ fn test_init_and_delete_module() { #[test] fn test_init_and_delete_module_with_params() { require_capability!(CAP_SYS_MODULE); - let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); - let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module(); @@ -121,8 +121,8 @@ fn test_init_and_delete_module_with_params() { #[test] fn test_finit_module_invalid() { require_capability!(CAP_SYS_MODULE); - let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); - let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); let kmod_path = "/dev/zero"; @@ -135,8 +135,8 @@ fn test_finit_module_invalid() { #[test] fn test_finit_module_twice_and_delete_module() { require_capability!(CAP_SYS_MODULE); - let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); - let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module(); @@ -157,8 +157,8 @@ fn test_finit_module_twice_and_delete_module() { #[test] fn test_delete_module_not_loaded() { require_capability!(CAP_SYS_MODULE); - let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); - let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); let result = delete_module(&CString::new("hello").unwrap(), DeleteModuleFlags::empty()); diff --git a/test/test_mount.rs b/test/test_mount.rs index d2e08bc428..605276b5b3 100644 --- a/test/test_mount.rs +++ b/test/test_mount.rs @@ -3,10 +3,6 @@ // namespaces (Linux >= 3.8 compiled with CONFIG_USER_NS), the test should run // without root. -extern crate libc; -extern crate nix; -extern crate tempfile; - #[cfg(target_os = "linux")] mod test_mount { use std::fs::{self, File}; diff --git a/test/test_pty.rs b/test/test_pty.rs index 2608c90484..1e0858770e 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -29,7 +29,7 @@ fn test_explicit_close() { #[test] #[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptsname_equivalence() { - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master let master_fd = posix_openpt(OFlag::O_RDWR).unwrap(); @@ -46,7 +46,7 @@ fn test_ptsname_equivalence() { #[test] #[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptsname_copy() { - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master let master_fd = posix_openpt(OFlag::O_RDWR).unwrap(); @@ -80,7 +80,7 @@ fn test_ptsname_r_copy() { #[test] #[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptsname_unique() { - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master let master1_fd = posix_openpt(OFlag::O_RDWR).unwrap(); @@ -98,7 +98,7 @@ fn test_ptsname_unique() { /// Common setup for testing PTTY pairs fn open_ptty_pair() -> (PtyMaster, File) { - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master let master = posix_openpt(OFlag::O_RDWR).expect("posix_openpt failed"); @@ -163,7 +163,7 @@ fn test_write_ptty_pair() { #[test] fn test_openpty() { // openpty uses ptname(3) internally - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); let pty = openpty(None, None).unwrap(); assert!(pty.master > 0); @@ -173,21 +173,21 @@ fn test_openpty() { let string = "foofoofoo\n"; let mut buf = [0u8; 10]; write(pty.master, string.as_bytes()).unwrap(); - ::read_exact(pty.slave, &mut buf); + crate::read_exact(pty.slave, &mut buf); assert_eq!(&buf, string.as_bytes()); // Read the echo as well let echoed_string = "foofoofoo\r\n"; let mut buf = [0u8; 11]; - ::read_exact(pty.master, &mut buf); + crate::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string.as_bytes()); let string2 = "barbarbarbar\n"; let echoed_string2 = "barbarbarbar\r\n"; let mut buf = [0u8; 14]; write(pty.slave, string2.as_bytes()).unwrap(); - ::read_exact(pty.master, &mut buf); + crate::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string2.as_bytes()); @@ -198,7 +198,7 @@ fn test_openpty() { #[test] fn test_openpty_with_termios() { // openpty uses ptname(3) internally - let _m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open one pty to get attributes for the second one let mut termios = { @@ -222,20 +222,20 @@ fn test_openpty_with_termios() { let string = "foofoofoo\n"; let mut buf = [0u8; 10]; write(pty.master, string.as_bytes()).unwrap(); - ::read_exact(pty.slave, &mut buf); + crate::read_exact(pty.slave, &mut buf); assert_eq!(&buf, string.as_bytes()); // read the echo as well let echoed_string = "foofoofoo\n"; - ::read_exact(pty.master, &mut buf); + crate::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string.as_bytes()); let string2 = "barbarbarbar\n"; let echoed_string2 = "barbarbarbar\n"; let mut buf = [0u8; 13]; write(pty.slave, string2.as_bytes()).unwrap(); - ::read_exact(pty.master, &mut buf); + crate::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string2.as_bytes()); @@ -249,9 +249,9 @@ fn test_forkpty() { use nix::sys::signal::*; use nix::sys::wait::wait; // forkpty calls openpty which uses ptname(3) internally. - let _m0 = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + let _m0 = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // forkpty spawns a child process - let _m1 = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m1 = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); let string = "naninani\n"; let echoed_string = "naninani\r\n"; @@ -265,7 +265,7 @@ fn test_forkpty() { Parent { child } => { let mut buf = [0u8; 10]; assert!(child.as_raw() > 0); - ::read_exact(pty.master, &mut buf); + crate::read_exact(pty.master, &mut buf); kill(child, SIGTERM).unwrap(); wait().unwrap(); // keep other tests using generic wait from getting our child assert_eq!(&buf, echoed_string.as_bytes()); diff --git a/test/test_ptymaster_drop.rs b/test/test_ptymaster_drop.rs index 9b59d66435..5a5c55d48d 100644 --- a/test/test_ptymaster_drop.rs +++ b/test/test_ptymaster_drop.rs @@ -1,21 +1,24 @@ -extern crate nix; +#[cfg(not(target_os = "redox"))] +mod t { + use nix::fcntl::OFlag; + use nix::pty::*; + use nix::unistd::close; + use std::os::unix::io::AsRawFd; -use nix::fcntl::OFlag; -use nix::pty::*; -use nix::unistd::close; -use std::os::unix::io::AsRawFd; - -/// Regression test for Issue #659 -/// `PtyMaster` should panic rather than double close the file descriptor -/// This must run in its own test process because it deliberately creates a race -/// condition. -#[test] -#[should_panic(expected = "Closing an invalid file descriptor!")] -// In Travis on i686-unknown-linux-musl, this test gets SIGABRT. I don't know -// why. It doesn't happen on any other target, and it doesn't happen on my PC. -#[cfg_attr(all(target_env = "musl", target_arch = "x86"), ignore)] -fn test_double_close() { - let m = posix_openpt(OFlag::O_RDWR).unwrap(); - close(m.as_raw_fd()).unwrap(); - drop(m); // should panic here + /// Regression test for Issue #659 + /// + /// `PtyMaster` should panic rather than double close the file descriptor + /// This must run in its own test process because it deliberately creates a + /// race condition. + #[test] + #[should_panic(expected = "Closing an invalid file descriptor!")] + // In Travis on i686-unknown-linux-musl, this test gets SIGABRT. I don't + // know why. It doesn't happen on any other target, and it doesn't happen + // on my PC. + #[cfg_attr(all(target_env = "musl", target_arch = "x86"), ignore)] + fn test_double_close() { + let m = posix_openpt(OFlag::O_RDWR).unwrap(); + close(m.as_raw_fd()).unwrap(); + drop(m); // should panic here + } } diff --git a/test/test_stat.rs b/test/test_stat.rs index 14a2b06c0b..0b94666856 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -172,7 +172,7 @@ fn test_fchmod() { #[test] #[cfg(not(target_os = "redox"))] fn test_fchmodat() { - let _dr = ::DirRestore::new(); + let _dr = crate::DirRestore::new(); let tempdir = tempfile::tempdir().unwrap(); let filename = "foo.txt"; let fullpath = tempdir.path().join(filename); @@ -264,7 +264,7 @@ fn test_futimens() { #[test] #[cfg(not(target_os = "redox"))] fn test_utimensat() { - let _dr = ::DirRestore::new(); + let _dr = crate::DirRestore::new(); let tempdir = tempfile::tempdir().unwrap(); let filename = "foo.txt"; let fullpath = tempdir.path().join(filename); diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 08ea2f6888..0a41b65f5d 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -18,13 +18,13 @@ use std::fs::DirBuilder; use std::fs::{self, File}; use std::io::Write; use std::os::unix::prelude::*; -use tempfile::{self, tempfile}; +use tempfile::{tempdir, tempfile}; use libc::{_exit, off_t}; #[test] #[cfg(not(any(target_os = "netbsd")))] fn test_fork_and_waitpid() { - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: Child only calls `_exit`, which is signal-safe match fork().expect("Error: Fork Failed") { @@ -52,7 +52,7 @@ fn test_fork_and_waitpid() { #[test] fn test_wait() { // Grab FORK_MTX so wait doesn't reap a different test's child process - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: Child only calls `_exit`, which is signal-safe match fork().expect("Error: Fork Failed") { @@ -90,7 +90,7 @@ fn test_mkstemp_directory() { #[test] #[cfg(not(target_os = "redox"))] fn test_mkfifo() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let mkfifo_fifo = tempdir.path().join("mkfifo_fifo"); mkfifo(&mkfifo_fifo, Mode::S_IRUSR).unwrap(); @@ -112,9 +112,9 @@ fn test_mkfifo_directory() { target_os = "macos", target_os = "ios", target_os = "android", target_os = "redox")))] fn test_mkfifoat_none() { - let _m = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let mkfifoat_fifo = tempdir.path().join("mkfifoat_fifo"); mkfifoat(None, &mkfifoat_fifo, Mode::S_IRUSR).unwrap(); @@ -129,7 +129,7 @@ fn test_mkfifoat_none() { target_os = "macos", target_os = "ios", target_os = "android", target_os = "redox")))] fn test_mkfifoat() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); let mkfifoat_name = "mkfifoat_name"; @@ -145,7 +145,7 @@ fn test_mkfifoat() { target_os = "macos", target_os = "ios", target_os = "android", target_os = "redox")))] fn test_mkfifoat_directory_none() { - let _m = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); // mkfifoat should fail if a directory is given assert!(!mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_ok()); @@ -157,7 +157,7 @@ fn test_mkfifoat_directory_none() { target_os = "android", target_os = "redox")))] fn test_mkfifoat_directory() { // mkfifoat should fail if a directory is given - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); let mkfifoat_dir = "mkfifoat_dir"; stat::mkdirat(dirfd, mkfifoat_dir, Mode::S_IRUSR).unwrap(); @@ -200,7 +200,7 @@ fn test_setgroups() { // Skip this test when not run as root as `setgroups()` requires root. skip_if_not_root!("test_setgroups"); - let _m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); // Save the existing groups let old_groups = getgroups().unwrap(); @@ -224,7 +224,7 @@ fn test_initgroups() { // require root. skip_if_not_root!("test_initgroups"); - let _m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); // Save the existing groups let old_groups = getgroups().unwrap(); @@ -259,7 +259,7 @@ macro_rules! execve_test_factory( skip_if_seccomp!($test_name); } - let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // The `exec`d process will write to `writer`, and we'll read that // data from `reader`. let (reader, writer) = pipe().unwrap(); @@ -353,9 +353,9 @@ cfg_if!{ #[test] fn test_fchdir() { // fchdir changes the process's cwd - let _dr = ::DirRestore::new(); + let _dr = crate::DirRestore::new(); - let tmpdir = tempfile::tempdir().unwrap(); + let tmpdir = tempdir().unwrap(); let tmpdir_path = tmpdir.path().canonicalize().unwrap(); let tmpdir_fd = File::open(&tmpdir_path).unwrap().into_raw_fd(); @@ -368,9 +368,9 @@ fn test_fchdir() { #[test] fn test_getcwd() { // chdir changes the process's cwd - let _dr = ::DirRestore::new(); + let _dr = crate::DirRestore::new(); - let tmpdir = tempfile::tempdir().unwrap(); + let tmpdir = tempdir().unwrap(); let tmpdir_path = tmpdir.path().canonicalize().unwrap(); assert!(chdir(&tmpdir_path).is_ok()); assert_eq!(getcwd().unwrap(), tmpdir_path); @@ -395,7 +395,7 @@ fn test_chown() { let uid = Some(getuid()); let gid = Some(getgid()); - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let path = tempdir.path().join("file"); { File::create(&path).unwrap(); @@ -412,12 +412,12 @@ fn test_chown() { #[test] #[cfg(not(target_os = "redox"))] fn test_fchownat() { - let _dr = ::DirRestore::new(); + let _dr = crate::DirRestore::new(); // Testing for anything other than our own UID/GID is hard. let uid = Some(getuid()); let gid = Some(getgid()); - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let path = tempdir.path().join("file"); { File::create(&path).unwrap(); @@ -445,7 +445,7 @@ fn test_lseek() { lseek(tmpfd, offset, Whence::SeekSet).unwrap(); let mut buf = [0u8; 7]; - ::read_exact(tmpfd, &mut buf); + crate::read_exact(tmpfd, &mut buf); assert_eq!(b"f123456", &buf); close(tmpfd).unwrap(); @@ -462,7 +462,7 @@ fn test_lseek64() { lseek64(tmpfd, 5, Whence::SeekSet).unwrap(); let mut buf = [0u8; 7]; - ::read_exact(tmpfd, &mut buf); + crate::read_exact(tmpfd, &mut buf); assert_eq!(b"f123456", &buf); close(tmpfd).unwrap(); @@ -498,7 +498,7 @@ fn test_acct() { use std::process::Command; use std::{thread, time}; - let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); require_acct!(); let file = NamedTempFile::new().unwrap(); @@ -573,7 +573,7 @@ fn test_pipe2() { #[test] #[cfg(not(target_os = "redox"))] fn test_truncate() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let path = tempdir.path().join("file"); { @@ -590,7 +590,7 @@ fn test_truncate() { #[test] fn test_ftruncate() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let path = tempdir.path().join("file"); let tmpfd = { @@ -621,7 +621,7 @@ pub extern fn alarm_signal_handler(raw_signal: libc::c_int) { #[test] #[cfg(not(target_os = "redox"))] fn test_alarm() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); let handler = SigHandler::Handler(alarm_signal_handler); let signal_action = SigAction::new(handler, SaFlags::SA_RESTART, SigSet::empty()); @@ -651,7 +651,7 @@ fn test_alarm() { #[test] #[cfg(not(target_os = "redox"))] fn test_canceling_alarm() { - let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); + let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); assert_eq!(alarm::cancel(), None); @@ -662,9 +662,9 @@ fn test_canceling_alarm() { #[test] #[cfg(not(target_os = "redox"))] fn test_symlinkat() { - let _m = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let target = tempdir.path().join("a"); let linkpath = tempdir.path().join("b"); @@ -690,7 +690,7 @@ fn test_symlinkat() { #[test] #[cfg(not(target_os = "redox"))] fn test_linkat_file() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let oldfilename = "foo.txt"; let oldfilepath = tempdir.path().join(oldfilename); @@ -711,13 +711,13 @@ fn test_linkat_file() { #[test] #[cfg(not(target_os = "redox"))] fn test_linkat_olddirfd_none() { - let _dr = ::DirRestore::new(); + let _dr = crate::DirRestore::new(); - let tempdir_oldfile = tempfile::tempdir().unwrap(); + let tempdir_oldfile = tempdir().unwrap(); let oldfilename = "foo.txt"; let oldfilepath = tempdir_oldfile.path().join(oldfilename); - let tempdir_newfile = tempfile::tempdir().unwrap(); + let tempdir_newfile = tempdir().unwrap(); let newfilename = "bar.txt"; let newfilepath = tempdir_newfile.path().join(newfilename); @@ -736,13 +736,13 @@ fn test_linkat_olddirfd_none() { #[test] #[cfg(not(target_os = "redox"))] fn test_linkat_newdirfd_none() { - let _dr = ::DirRestore::new(); + let _dr = crate::DirRestore::new(); - let tempdir_oldfile = tempfile::tempdir().unwrap(); + let tempdir_oldfile = tempdir().unwrap(); let oldfilename = "foo.txt"; let oldfilepath = tempdir_oldfile.path().join(oldfilename); - let tempdir_newfile = tempfile::tempdir().unwrap(); + let tempdir_newfile = tempdir().unwrap(); let newfilename = "bar.txt"; let newfilepath = tempdir_newfile.path().join(newfilename); @@ -761,9 +761,9 @@ fn test_linkat_newdirfd_none() { #[test] #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] fn test_linkat_no_follow_symlink() { - let _m = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let oldfilename = "foo.txt"; let oldfilepath = tempdir.path().join(oldfilename); @@ -798,9 +798,9 @@ fn test_linkat_no_follow_symlink() { #[test] #[cfg(not(target_os = "redox"))] fn test_linkat_follow_symlink() { - let _m = ::CWD_LOCK.read().expect("Mutex got poisoned by another test"); + let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test"); - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let oldfilename = "foo.txt"; let oldfilepath = tempdir.path().join(oldfilename); @@ -834,7 +834,7 @@ fn test_linkat_follow_symlink() { #[test] #[cfg(not(target_os = "redox"))] fn test_unlinkat_dir_noremovedir() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let dirname = "foo_dir"; let dirpath = tempdir.path().join(dirname); @@ -852,7 +852,7 @@ fn test_unlinkat_dir_noremovedir() { #[test] #[cfg(not(target_os = "redox"))] fn test_unlinkat_dir_removedir() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let dirname = "foo_dir"; let dirpath = tempdir.path().join(dirname); @@ -870,7 +870,7 @@ fn test_unlinkat_dir_removedir() { #[test] #[cfg(not(target_os = "redox"))] fn test_unlinkat_file() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let filename = "foo.txt"; let filepath = tempdir.path().join(filename); @@ -887,7 +887,7 @@ fn test_unlinkat_file() { #[test] fn test_access_not_existing() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let dir = tempdir.path().join("does_not_exist.txt"); assert_eq!(access(&dir, AccessFlags::F_OK).err().unwrap().as_errno().unwrap(), Errno::ENOENT); @@ -895,7 +895,7 @@ fn test_access_not_existing() { #[test] fn test_access_file_exists() { - let tempdir = tempfile::tempdir().unwrap(); + let tempdir = tempdir().unwrap(); let path = tempdir.path().join("does_exist.txt"); let _file = File::create(path.clone()).unwrap(); assert!(access(&path, AccessFlags::R_OK | AccessFlags::W_OK).is_ok());