summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryant Mairs <bryantmairs@google.com>2017-11-21 22:27:15 -0800
committerBryant Mairs <bryantmairs@google.com>2017-12-02 10:46:34 -0800
commite1baab9dc132f18e13f446df0271a5e46723848d (patch)
tree3e4e6714d843edc493dfc3cf879d659bbd264e65
parentd374a1ecd3f69027a2ce28e87806f459ef3f9105 (diff)
downloadnix-e1baab9dc132f18e13f446df0271a5e46723848d.zip
Upgrade to Bitflags 1.0
The libc_bitflags! macro was replaced with a non-recursive one supporting only public structs. I could not figure out how to make the old macro work with the upgrade, so I reworked part of the bitflags! macro directly to suit our needs, much as the original recursive macro was made. There are no uses of this macro for non-public structs, so this is not a problem for internal code.
-rw-r--r--.travis.yml58
-rw-r--r--Cargo.toml2
-rw-r--r--README.md8
-rw-r--r--src/macros.rs211
-rw-r--r--src/mqueue.rs2
-rw-r--r--src/pty.rs10
-rw-r--r--src/sys/event.rs4
-rw-r--r--src/sys/quota.rs20
-rw-r--r--src/sys/signal.rs10
-rw-r--r--src/sys/signalfd.rs6
-rw-r--r--src/sys/socket/mod.rs34
-rw-r--r--src/sys/termios.rs6
-rw-r--r--src/unistd.rs26
-rw-r--r--test/sys/test_aio.rs6
-rw-r--r--test/sys/test_epoll.rs5
-rw-r--r--test/sys/test_ptrace.rs4
-rw-r--r--test/sys/test_socket.rs10
-rw-r--r--test/sys/test_termios.rs12
-rw-r--r--test/sys/test_uio.rs1
-rw-r--r--test/sys/test_wait.rs5
-rw-r--r--test/test_fcntl.rs4
-rw-r--r--test/test_mount.rs22
-rw-r--r--test/test_mq.rs30
-rw-r--r--test/test_poll.rs15
-rw-r--r--test/test_pty.rs20
-rw-r--r--test/test_ptymaster_drop.rs4
-rw-r--r--test/test_unistd.rs25
27 files changed, 188 insertions, 372 deletions
diff --git a/.travis.yml b/.travis.yml
index c8caf483..1553ce4f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,67 +18,67 @@ matrix:
include:
# Android
- env: TARGET=aarch64-linux-android DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=arm-linux-androideabi DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=aarch64-apple-ios DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
os: osx
- env: TARGET=i686-linux-android DISABLE_TESTS=1
- rust: 1.18.0
+ rust: 1.20.0
- env: TARGET=x86_64-linux-android DISABLE_TESTS=1
- rust: 1.18.0
+ rust: 1.20.0
# Linux
- env: TARGET=aarch64-unknown-linux-gnu
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=armv7-apple-ios DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
os: osx
- env: TARGET=arm-unknown-linux-gnueabi
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=arm-unknown-linux-musleabi DISABLE_TESTS=1
- rust: 1.14.0
+ rust: 1.20.0
- env: TARGET=armv7-unknown-linux-gnueabihf
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=armv7s-apple-ios DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
os: osx
- env: TARGET=i686-unknown-linux-gnu
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=i686-unknown-linux-musl
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=mips-unknown-linux-gnu
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=i386-apple-ios DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
os: osx
- env: TARGET=mips64-unknown-linux-gnuabi64
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=mips64el-unknown-linux-gnuabi64
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=mipsel-unknown-linux-gnu
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=x86_64-apple-ios DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
os: osx
- env: TARGET=powerpc-unknown-linux-gnu DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=powerpc64-unknown-linux-gnu
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=powerpc64le-unknown-linux-gnu
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=i686-apple-darwin
- rust: 1.13.0
+ rust: 1.20.0
os: osx
- env: TARGET=s390x-unknown-linux-gnu DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=x86_64-unknown-linux-gnu
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=x86_64-unknown-linux-musl
- rust: 1.13.0
+ rust: 1.20.0
# *BSD
# FreeBSD i686 and x86_64 use BuildBot instead of Travis
@@ -87,10 +87,10 @@ matrix:
# - env: TARGET=i686-unknown-freebsd DISABLE_TESTS=1
# - env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1
- env: TARGET=x86_64-unknown-netbsd DISABLE_TESTS=1
- rust: 1.13.0
+ rust: 1.20.0
- env: TARGET=x86_64-apple-darwin
- rust: 1.13.0
+ rust: 1.20.0
os: osx
# Make sure stable is always working too
diff --git a/Cargo.toml b/Cargo.toml
index fd63573c..f9e37545 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,7 @@ exclude = [
[dependencies]
libc = { git = "https://github.com/rust-lang/libc" }
-bitflags = "0.9"
+bitflags = "1.0"
cfg-if = "0.1.0"
void = "1.0.2"
diff --git a/README.md b/README.md
index 5146d57c..5ca0ccdf 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ limitations. Support for platforms is split into two tiers:
*do not* block the inclusion of new code. Testing may be run, but
failures in tests don't block the inclusion of new code.
-The following targets are all supported by nix on Rust 1.13.0 or newer (unless
+The following targets are all supported by nix on Rust 1.20.0 or newer (unless
otherwise noted):
Tier 1:
@@ -72,16 +72,16 @@ Tier 2:
* aarch64-apple-ios
* aarch64-linux-android
* arm-linux-androideabi
- * arm-unknown-linux-musleabi (requires Rust >= 1.14)
+ * arm-unknown-linux-musleabi
* armv7-apple-ios
* armv7-linux-androideabi
* armv7s-apple-ios
* i386-apple-ios
- * i686-linux-android (requires Rust >= 1.18)
+ * i686-linux-android
* powerpc-unknown-linux-gnu
* s390x-unknown-linux-gnu
* x86_64-apple-ios
- * x86_64-linux-android (requires Rust >= 1.18)
+ * x86_64-linux-android
* x86_64-unknown-netbsd
## Usage
diff --git a/src/macros.rs b/src/macros.rs
index 39bc466d..15f7505c 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -1,6 +1,6 @@
-/// The `libc_bitflags!` macro helps with a common use case of defining bitflags with values from
-/// the libc crate. It is used the same way as the `bitflags!` macro, except that only the name of
-/// the flag value has to be given.
+/// The `libc_bitflags!` macro helps with a common use case of defining a public bitflags type
+/// with values from the libc crate. It is used the same way as the `bitflags!` macro, except
+/// that only the name of the flag value has to be given.
///
/// The `libc` crate must be in scope with the name `libc`.
///
@@ -10,6 +10,7 @@
/// pub struct ProtFlags: libc::c_int {
/// PROT_NONE;
/// PROT_READ;
+/// /// PROT_WRITE enables write protect
/// PROT_WRITE;
/// PROT_EXEC;
/// #[cfg(any(target_os = "linux", target_os = "android"))]
@@ -38,205 +39,25 @@
/// }
/// ```
macro_rules! libc_bitflags {
- // (non-pub) Exit rule.
- (@call_bitflags
- {
- name: $BitFlags:ident,
- type: $T:ty,
- attrs: [$($attrs:tt)*],
- flags: [$($flags:tt)*],
- }
- ) => {
- bitflags! {
- $($attrs)*
- struct $BitFlags: $T {
- $($flags)*
- }
- }
- };
-
- // (pub) Exit rule.
- (@call_bitflags
- {
- pub,
- name: $BitFlags:ident,
- type: $T:ty,
- attrs: [$($attrs:tt)*],
- flags: [$($flags:tt)*],
+ (
+ $(#[$outer:meta])*
+ pub struct $BitFlags:ident: $T:ty {
+ $(
+ $(#[$inner:ident $($args:tt)*])*
+ $Flag:ident $(as $cast:ty)*;
+ )+
}
) => {
bitflags! {
- $($attrs)*
+ $(#[$outer])*
pub struct $BitFlags: $T {
- $($flags)*
- }
- }
- };
-
- // (non-pub) Done accumulating.
- (@accumulate_flags
- {
- name: $BitFlags:ident,
- type: $T:ty,
- attrs: $attrs:tt,
- },
- $flags:tt;
- ) => {
- libc_bitflags! {
- @call_bitflags
- {
- name: $BitFlags,
- type: $T,
- attrs: $attrs,
- flags: $flags,
+ $(
+ $(#[$inner $($args)*])*
+ const $Flag = libc::$Flag $(as $cast)*;
+ )+
}
}
};
-
- // (pub) Done accumulating.
- (@accumulate_flags
- {
- pub,
- name: $BitFlags:ident,
- type: $T:ty,
- attrs: $attrs:tt,
- },
- $flags:tt;
- ) => {
- libc_bitflags! {
- @call_bitflags
- {
- pub,
- name: $BitFlags,
- type: $T,
- attrs: $attrs,
- flags: $flags,
- }
- }
- };
-
- // Munch an attr.
- (@accumulate_flags
- $prefix:tt,
- [$($flags:tt)*];
- #[$attr:meta] $($tail:tt)*
- ) => {
- libc_bitflags! {
- @accumulate_flags
- $prefix,
- [
- $($flags)*
- #[$attr]
- ];
- $($tail)*
- }
- };
-
- // Munch last ident if not followed by a semicolon.
- (@accumulate_flags
- $prefix:tt,
- [$($flags:tt)*];
- $flag:ident
- ) => {
- libc_bitflags! {
- @accumulate_flags
- $prefix,
- [
- $($flags)*
- const $flag = libc::$flag;
- ];
- }
- };
-
- // Munch last ident and cast it to the given type.
- (@accumulate_flags
- $prefix:tt,
- [$($flags:tt)*];
- $flag:ident as $ty:ty
- ) => {
- libc_bitflags! {
- @accumulate_flags
- $prefix,
- [
- $($flags)*
- const $flag = libc::$flag as $ty;
- ];
- }
- };
-
- // Munch an ident; covers terminating semicolon case.
- (@accumulate_flags
- $prefix:tt,
- [$($flags:tt)*];
- $flag:ident; $($tail:tt)*
- ) => {
- libc_bitflags! {
- @accumulate_flags
- $prefix,
- [
- $($flags)*
- const $flag = libc::$flag;
- ];
- $($tail)*
- }
- };
-
- // Munch an ident and cast it to the given type; covers terminating semicolon
- // case.
- (@accumulate_flags
- $prefix:tt,
- [$($flags:tt)*];
- $flag:ident as $ty:ty; $($tail:tt)*
- ) => {
- libc_bitflags! {
- @accumulate_flags
- $prefix,
- [
- $($flags)*
- const $flag = libc::$flag as $ty;
- ];
- $($tail)*
- }
- };
-
- // (non-pub) Entry rule.
- (
- $(#[$attr:meta])*
- struct $BitFlags:ident: $T:ty {
- $($vals:tt)*
- }
- ) => {
- libc_bitflags! {
- @accumulate_flags
- {
- name: $BitFlags,
- type: $T,
- attrs: [$(#[$attr])*],
- },
- [];
- $($vals)*
- }
- };
-
- // (pub) Entry rule.
- (
- $(#[$attr:meta])*
- pub struct $BitFlags:ident: $T:ty {
- $($vals:tt)*
- }
- ) => {
- libc_bitflags! {
- @accumulate_flags
- {
- pub,
- name: $BitFlags,
- type: $T,
- attrs: [$(#[$attr])*],
- },
- [];
- $($vals)*
- }
- };
}
/// The `libc_enum!` macro helps with a common use case of defining an enum exclusively using
diff --git a/src/mqueue.rs b/src/mqueue.rs
index b4a791c9..4c88045c 100644
--- a/src/mqueue.rs
+++ b/src/mqueue.rs
@@ -151,7 +151,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
/// Returns the old attributes
pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
let oldattr = try!(mq_getattr(mqd));
- let newattr = MqAttr::new(O_NONBLOCK.bits() as c_long,
+ let newattr = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long,
oldattr.mq_attr.mq_maxmsg,
oldattr.mq_attr.mq_msgsize,
oldattr.mq_attr.mq_curmsgs);
diff --git a/src/pty.rs b/src/pty.rs
index 98443d61..dbf34208 100644
--- a/src/pty.rs
+++ b/src/pty.rs
@@ -86,14 +86,14 @@ pub fn grantpt(fd: &PtyMaster) -> Result<()> {
///
/// ```
/// use std::path::Path;
-/// use nix::fcntl::{O_RDWR, open};
-/// use nix::pty::*;
-/// use nix::sys::stat;
+/// use nix::fcntl::{OFlag, open};
+/// use nix::pty::{grantpt, posix_openpt, ptsname, unlockpt};
+/// use nix::sys::stat::Mode;
///
/// # #[allow(dead_code)]
/// # fn run() -> nix::Result<()> {
/// // Open a new PTY master
-/// let master_fd = posix_openpt(O_RDWR)?;
+/// let master_fd = posix_openpt(OFlag::O_RDWR)?;
///
/// // Allow a slave to be generated for it
/// grantpt(&master_fd)?;
@@ -104,7 +104,7 @@ pub fn grantpt(fd: &PtyMaster) -> Result<()> {
///
/// // Try to open the slave
/// # #[allow(unused_variables)]
-/// let slave_fd = open(Path::new(&slave_name), O_RDWR, stat::Mode::empty())?;
+/// let slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, Mode::empty())?;
/// # Ok(())
/// # }
/// ```
diff --git a/src/sys/event.rs b/src/sys/event.rs
index 189f8239..e63fe502 100644
--- a/src/sys/event.rs
+++ b/src/sys/event.rs
@@ -320,8 +320,8 @@ fn test_struct_kevent() {
udata: udata as type_of_udata};
let actual = KEvent::new(0xdeadbeef,
EventFilter::EVFILT_READ,
- EV_ONESHOT | EV_ADD,
- NOTE_CHILD | NOTE_EXIT,
+ EventFlag::EV_ONESHOT | EventFlag::EV_ADD,
+ FilterFlag::NOTE_CHILD | FilterFlag::NOTE_EXIT,
0x1337,
udata);
assert!(expected.ident == actual.ident());
diff --git a/src/sys/quota.rs b/src/sys/quota.rs
index 77b13335..4a8fdf5e 100644
--- a/src/sys/quota.rs
+++ b/src/sys/quota.rs
@@ -5,12 +5,12 @@
//! Enabling and setting a quota:
//!
//! ```rust,no_run
-//! # use nix::sys::quota::*;
+//! # use nix::sys::quota::{Dqblk, quotactl_on, quotactl_set, QuotaFmt, QuotaType, QuotaValidFlags};
//! quotactl_on(QuotaType::USRQUOTA, "/dev/sda1", QuotaFmt::QFMT_VFS_V1, "aquota.user");
//! let mut dqblk: Dqblk = Default::default();
//! dqblk.set_blocks_hard_limit(10000);
//! dqblk.set_blocks_soft_limit(8000);
-//! quotactl_set(QuotaType::USRQUOTA, "/dev/sda1", 50, &dqblk, QIF_BLIMITS);
+//! quotactl_set(QuotaType::USRQUOTA, "/dev/sda1", 50, &dqblk, QuotaValidFlags::QIF_BLIMITS);
//! ```
use std::default::Default;
use std::{mem, ptr};
@@ -121,7 +121,7 @@ impl Dqblk {
/// The absolute limit on disk quota blocks allocated.
pub fn blocks_hard_limit(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_BLIMITS) {
+ if valid_fields.contains(QuotaValidFlags::QIF_BLIMITS) {
Some(self.0.dqb_bhardlimit)
} else {
None
@@ -136,7 +136,7 @@ impl Dqblk {
/// Preferred limit on disk quota blocks
pub fn blocks_soft_limit(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_BLIMITS) {
+ if valid_fields.contains(QuotaValidFlags::QIF_BLIMITS) {
Some(self.0.dqb_bsoftlimit)
} else {
None
@@ -151,7 +151,7 @@ impl Dqblk {
/// Current occupied space (bytes).
pub fn occupied_space(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_SPACE) {
+ if valid_fields.contains(QuotaValidFlags::QIF_SPACE) {
Some(self.0.dqb_curspace)
} else {
None
@@ -161,7 +161,7 @@ impl Dqblk {
/// Maximum number of allocated inodes.
pub fn inodes_hard_limit(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_ILIMITS) {
+ if valid_fields.contains(QuotaValidFlags::QIF_ILIMITS) {
Some(self.0.dqb_ihardlimit)
} else {
None
@@ -176,7 +176,7 @@ impl Dqblk {
/// Preferred inode limit
pub fn inodes_soft_limit(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_ILIMITS) {
+ if valid_fields.contains(QuotaValidFlags::QIF_ILIMITS) {
Some(self.0.dqb_isoftlimit)
} else {
None
@@ -191,7 +191,7 @@ impl Dqblk {
/// Current number of allocated inodes.
pub fn allocated_inodes(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_INODES) {
+ if valid_fields.contains(QuotaValidFlags::QIF_INODES) {
Some(self.0.dqb_curinodes)
} else {
None
@@ -201,7 +201,7 @@ impl Dqblk {
/// Time limit for excessive disk use.
pub fn block_time_limit(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_BTIME) {
+ if valid_fields.contains(QuotaValidFlags::QIF_BTIME) {
Some(self.0.dqb_btime)
} else {
None
@@ -216,7 +216,7 @@ impl Dqblk {
/// Time limit for excessive files.
pub fn inode_time_limit(&self) -> Option<u64> {
let valid_fields = QuotaValidFlags::from_bits_truncate(self.0.dqb_valid);
- if valid_fields.contains(QIF_ITIME) {
+ if valid_fields.contains(QuotaValidFlags::QIF_ITIME) {
Some(self.0.dqb_itime)
} else {
None
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 093fdb8e..967c6416 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -373,8 +373,8 @@ impl SigAction {
SigHandler::SigAction(f) => f as *const extern fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void) as usize,
};
s.sa_flags = match handler {
- SigHandler::SigAction(_) => (flags | SA_SIGINFO).bits(),
- _ => (flags - SA_SIGINFO).bits(),
+ SigHandler::SigAction(_) => (flags | SaFlags::SA_SIGINFO).bits(),
+ _ => (flags - SaFlags::SA_SIGINFO).bits(),
};
s.sa_mask = mask.sigset;
@@ -393,7 +393,7 @@ impl SigAction {
match self.sigaction.sa_sigaction {
libc::SIG_DFL => SigHandler::SigDfl,
libc::SIG_IGN => SigHandler::SigIgn,
- f if self.flags().contains(SA_SIGINFO) =>
+ f if self.flags().contains(SaFlags::SA_SIGINFO) =>
SigHandler::SigAction( unsafe { mem::transmute(f) } ),
f => SigHandler::Handler( unsafe { mem::transmute(f) } ),
}
@@ -713,14 +713,14 @@ mod tests {
let handler_sig = SigHandler::Handler(test_sigaction_handler);
- let flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
+ let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART | SaFlags::SA_SIGINFO;
let mut mask = SigSet::empty();
mask.add(SIGUSR1);
let action_sig = SigAction::new(handler_sig, flags, mask);
- assert_eq!(action_sig.flags(), SA_ONSTACK | SA_RESTART);
+ assert_eq!(action_sig.flags(), SaFlags::SA_ONSTACK | SaFlags::SA_RESTART);
assert_eq!(action_sig.handler(), handler_sig);
mask = action_sig.mask();
diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs
index abc96b8c..bbd38b23 100644
--- a/src/sys/signalfd.rs
+++ b/src/sys/signalfd.rs
@@ -67,7 +67,7 @@ pub fn signalfd(fd: RawFd, mask: &SigSet, flags: SfdFlags) -> Result<RawFd> {
/// mask.thread_block().unwrap();
///
/// // Signals are queued up on the file descriptor
-/// let mut sfd = SignalFd::with_flags(&mask, SFD_NONBLOCK).unwrap();
+/// let mut sfd = SignalFd::with_flags(&mask, SfdFlags::SFD_NONBLOCK).unwrap();
///
/// match sfd.read_signal() {
/// // we caught a signal
@@ -155,14 +155,14 @@ mod tests {
#[test]
fn create_signalfd_with_opts() {
let mask = SigSet::empty();
- let fd = SignalFd::with_flags(&mask, SFD_CLOEXEC | SFD_NONBLOCK);
+ let fd = SignalFd::with_flags(&mask, SfdFlags::SFD_CLOEXEC | SfdFlags::SFD_NONBLOCK);
assert!(fd.is_ok());
}
#[test]
fn read_empty_signalfd() {
let mask = SigSet::empty();
- let mut fd = SignalFd::with_flags(&mask, SFD_NONBLOCK).unwrap();
+ let mut fd = SignalFd::with_flags(&mask, SfdFlags::SFD_NONBLOCK).unwrap();
let res = fd.read_signal();
assert!(res.unwrap().is_none());
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index e333f005..cdb8b4b3 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -571,16 +571,16 @@ pub fn socket<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: SockType
target_os = "netbsd",
target_os = "openbsd"))]
{
- use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
+ use fcntl::{fcntl, FdFlag, OFlag};
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
if !feat_atomic {
- if flags.contains(SOCK_CLOEXEC) {
- try!(fcntl(res, F_SETFD(FD_CLOEXEC)));
+ if flags.contains(SockFlag::SOCK_CLOEXEC) {
+ try!(fcntl(res, F_SETFD(FdFlag::FD_CLOEXEC)));
}
- if flags.contains(SOCK_NONBLOCK) {
- try!(fcntl(res, F_SETFL(O_NONBLOCK)));
+ if flags.contains(SockFlag::SOCK_NONBLOCK) {
+ try!(fcntl(res, F_SETFL(OFlag::O_NONBLOCK)));
}
}
}
@@ -616,18 +616,18 @@ pub fn socketpair<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: Sock
target_os = "netbsd",
target_os = "openbsd"))]
{
- use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
+ use fcntl::{fcntl, FdFlag, OFlag};
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
if !feat_atomic {
- if flags.contains(SOCK_CLOEXEC) {
- try!(fcntl(fds[0], F_SETFD(FD_CLOEXEC)));
- try!(fcntl(fds[1], F_SETFD(FD_CLOEXEC)));
+ if flags.contains(SockFlag::SOCK_CLOEXEC) {
+ try!(fcntl(fds[0], F_SETFD(FdFlag::FD_CLOEXEC)));
+ try!(fcntl(fds[1], F_SETFD(FdFlag::FD_CLOEXEC)));
}
- if flags.contains(SOCK_NONBLOCK) {
- try!(fcntl(fds[0], F_SETFL(O_NONBLOCK)));
- try!(fcntl(fds[1], F_SETFL(O_NONBLOCK)));
+ if flags.contains(SockFlag::SOCK_NONBLOCK) {
+ try!(fcntl(fds[0], F_SETFL(OFlag::O_NONBLOCK)));
+ try!(fcntl(fds[1], F_SETFL(OFlag::O_NONBLOCK)));
}
}
}
@@ -698,15 +698,15 @@ fn accept4_polyfill(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
target_os = "netbsd",
target_os = "openbsd"))]
{
- use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
+ use fcntl::{fcntl, FdFlag, OFlag};
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
- if flags.contains(SOCK_CLOEXEC) {
- try!(fcntl(res, F_SETFD(FD_CLOEXEC)));
+ if flags.contains(SockFlag::SOCK_CLOEXEC) {
+ try!(fcntl(res, F_SETFD(FdFlag::FD_CLOEXEC)));
}
- if flags.contains(SOCK_NONBLOCK) {
- try!(fcntl(res, F_SETFL(O_NONBLOCK)));
+ if flags.contains(SockFlag::SOCK_NONBLOCK) {
+ try!(fcntl(res, F_SETFL(OFlag::O_NONBLOCK)));
}
}
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 89f18ee1..34d960ff 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -37,10 +37,10 @@
//! An example showing some of the basic operations for interacting with the control flags:
//!
//! ```
-//! # use self::nix::sys::termios::{CS5, CSIZE, Termios};
+//! # use self::nix::sys::termios::{ControlFlags, Termios};
//! # let mut termios = unsafe { Termios::default_uninit() };
-//! termios.control_flags & CSIZE == CS5;
-//! termios.control_flags |= CS5;
+//! termios.control_flags & ControlFlags::CSIZE == ControlFlags::CS5;
+//! termios.control_flags |= ControlFlags::CS5;
//! ```
use {Errno, Result};
diff --git a/src/unistd.rs b/src/unistd.rs
index 52dfbb70..4e27d675 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -2,7 +2,7 @@
use errno;
use {Errno, Error, Result, NixPath};
-use fcntl::{fcntl, OFlag, O_CLOEXEC, FD_CLOEXEC};
+use fcntl::{fcntl, FdFlag, OFlag};
use 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};
@@ -322,7 +322,7 @@ pub fn gettid() -> Pid {
/// underlying resource, offset, and file status flags. The actual index used
/// for the file descriptor will be the lowest fd index that is available.
///
-/// The two file descriptors do not share file descriptor flags (e.g. `FD_CLOEXEC`).
+/// The two file descriptors do not share file descriptor flags (e.g. `OFlag::FD_CLOEXEC`).
#[inline]
pub fn dup(oldfd: RawFd) -> Result<RawFd> {
let res = unsafe { libc::dup(oldfd) };
@@ -360,8 +360,8 @@ fn dup3_polyfill(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> {
let fd = try!(dup2(oldfd, newfd));
- if flags.contains(O_CLOEXEC) {
- if let Err(e) = fcntl(fd, F_SETFD(FD_CLOEXEC)) {
+ if flags.contains(OFlag::O_CLOEXEC) {
+ if let Err(e) = fcntl(fd, F_SETFD(FdFlag::FD_CLOEXEC)) {
let _ = close(fd);
return Err(e);
}
@@ -422,7 +422,7 @@ pub fn fchdir(dirfd: RawFd) -> Result<()> {
/// let tmp_dir2 = tmp_dir1.path().join("new_dir");
///
/// // create new directory and give read, write and execute rights to the owner
-/// match unistd::mkdir(&tmp_dir2, stat::S_IRWXU) {
+/// match unistd::mkdir(&tmp_dir2, stat::Mode::S_IRWXU) {
/// Ok(_) => println!("created {:?}", tmp_dir2),
/// Err(err) => println!("Error creating directory: {}", err),
/// }
@@ -465,7 +465,7 @@ pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
/// let fifo_path = tmp_dir.path().join("foo.pipe");
///
/// // create new fifo and give read, write and execute rights to the owner
-/// match unistd::mkfifo(&fifo_path, stat::S_IRWXU) {
+/// match unistd::mkfifo(&fifo_path, stat::Mode::S_IRWXU) {
/// Ok(_) => println!("created {:?}", fifo_path),
/// Err(err) => println!("Error creating fifo: {}", err),
/// }
@@ -909,21 +909,21 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
target_os = "android",
target_os = "emscripten")))]
fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> {
- use fcntl::O_NONBLOCK;
+ use fcntl::FdFlag;
use fcntl::FcntlArg::F_SETFL;
let mut res = Ok(0);
- if flags.contains(O_CLOEXEC) {
+ if flags.contains(OFlag::O_CLOEXEC) {
res = res
- .and_then(|_| fcntl(fd1, F_SETFD(FD_CLOEXEC)))
- .and_then(|_| fcntl(fd2, F_SETFD(FD_CLOEXEC)));
+ .and_then(|_| fcntl(fd1, F_SETFD(FdFlag::FD_CLOEXEC)))
+ .and_then(|_| fcntl(fd2, F_SETFD(FdFlag::FD_CLOEXEC)));
}
- if flags.contains(O_NONBLOCK) {
+ if flags.contains(OFlag::O_NONBLOCK) {
res = res
- .and_then(|_| fcntl(fd1, F_SETFL(O_NONBLOCK)))
- .and_then(|_| fcntl(fd2, F_SETFL(O_NONBLOCK)));
+ .and_then(|_| fcntl(fd1, F_SETFL(OFlag::O_NONBLOCK)))
+ .and_then(|_| fcntl(fd2, F_SETFL(OFlag::O_NONBLOCK)));
}
match res {
diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs
index 630dff9a..79a6b6c4 100644
--- a/test/sys/test_aio.rs
+++ b/test/sys/test_aio.rs
@@ -2,7 +2,7 @@ use libc::c_int;
use nix::{Error, Result};
use nix::errno::*;
use nix::sys::aio::*;
-use nix::sys::signal::*;
+use nix::sys::signal::{SaFlags, SigAction, sigaction, SigevNotify, SigHandler, Signal, SigSet};
use nix::sys::time::{TimeSpec, TimeValLike};
use std::io::{Write, Read, Seek, SeekFrom};
use std::ops::Deref;
@@ -325,7 +325,7 @@ fn test_write_sigev_signal() {
#[allow(unused_variables)]
let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
let sa = SigAction::new(SigHandler::Handler(sigfunc),
- SA_RESETHAND,
+ SaFlags::SA_RESETHAND,
SigSet::empty());
SIGNALED.store(false, Ordering::Relaxed);
unsafe { sigaction(Signal::SIGUSR2, &sa) }.unwrap();
@@ -462,7 +462,7 @@ fn test_lio_listio_signal() {
const EXPECT: &'static [u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
let sa = SigAction::new(SigHandler::Handler(sigfunc),
- SA_RESETHAND,
+ SaFlags::SA_RESETHAND,
SigSet::empty());
let sigev_notify = SigevNotify::SigevSignal { signal: Signal::SIGUSR2,
si_value: 0 };
diff --git a/test/sys/test_epoll.rs b/test/sys/test_epoll.rs
index a73fea6d..e32a4e23 100644
--- a/test/sys/test_epoll.rs
+++ b/test/sys/test_epoll.rs
@@ -1,5 +1,4 @@
-use nix::sys::epoll::{EpollCreateFlags, EpollOp, EpollEvent};
-use nix::sys::epoll::{EPOLLIN, EPOLLERR};
+use nix::sys::epoll::{EpollCreateFlags, EpollFlags, EpollOp, EpollEvent};
use nix::sys::epoll::{epoll_create1, epoll_ctl};
use nix::{Error, Errno};
@@ -18,7 +17,7 @@ pub fn test_epoll_errno() {
#[test]
pub fn test_epoll_ctl() {
let efd = epoll_create1(EpollCreateFlags::empty()).unwrap();
- let mut event = EpollEvent::new(EPOLLIN | EPOLLERR, 1);
+ let mut event = EpollEvent::new(EpollFlags::EPOLLIN | EpollFlags::EPOLLERR, 1);
epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, &mut event).unwrap();
epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None).unwrap();
}
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs
index 20cde1aa..d3e579f3 100644
--- a/test/sys/test_ptrace.rs
+++ b/test/sys/test_ptrace.rs
@@ -1,7 +1,7 @@
use nix::Error;
use nix::errno::Errno;
use nix::unistd::getpid;
-use nix::sys::ptrace;
+use nix::sys::ptrace::{self, Options};
use std::mem;
@@ -16,7 +16,7 @@ fn test_ptrace() {
// Just make sure ptrace_setoptions can be called at all, for now.
#[test]
fn test_ptrace_setoptions() {
- let err = ptrace::setoptions(getpid(), ptrace::PTRACE_O_TRACESYSGOOD).unwrap_err();
+ let err = ptrace::setoptions(getpid(), Options::PTRACE_O_TRACESYSGOOD).unwrap_err();
assert!(err != Error::UnsupportedOperation);
}
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index b3d983d3..8ec7f1fd 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -122,8 +122,7 @@ pub fn test_scm_rights() {
use nix::unistd::{pipe, read, write, close};
use nix::sys::socket::{socketpair, sendmsg, recvmsg,
AddressFamily, SockType, SockFlag,
- ControlMessage, CmsgSpace, MsgFlags,
- MSG_TRUNC, MSG_CTRUNC};
+ ControlMessage, CmsgSpace, MsgFlags};
let (fd1, fd2) = socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::empty())
.unwrap();
@@ -154,7 +153,7 @@ pub fn test_scm_rights() {
panic!("unexpected cmsg");
}
}
- assert!(!msg.flags.intersects(MSG_TRUNC | MSG_CTRUNC));
+ assert!(!msg.flags.intersects(MsgFlags::MSG_TRUNC | MsgFlags::MSG_CTRUNC));
close(fd2).unwrap();
}
@@ -178,8 +177,7 @@ pub fn test_sendmsg_empty_cmsgs() {
use nix::unistd::close;
use nix::sys::socket::{socketpair, sendmsg, recvmsg,
AddressFamily, SockType, SockFlag,
- CmsgSpace, MsgFlags,
- MSG_TRUNC, MSG_CTRUNC};
+ CmsgSpace, MsgFlags};
let (fd1, fd2) = socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::empty())
.unwrap();
@@ -199,7 +197,7 @@ pub fn test_sendmsg_empty_cmsgs() {
for _ in msg.cmsgs() {
panic!("unexpected cmsg");
}
- assert!(!msg.flags.intersects(MSG_TRUNC | MSG_CTRUNC));
+ assert!(!msg.flags.intersects(MsgFlags::MSG_TRUNC | MsgFlags::MSG_CTRUNC));
close(fd2).unwrap();
}
}
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index 6640c3af..a3a948b3 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -4,7 +4,7 @@ use tempfile::tempfile;
use nix::{Error, fcntl};
use nix::errno::Errno;
use nix::pty::openpty;
-use nix::sys::termios::{self, ECHO, OPOST, OCRNL, Termios, tcgetattr};
+use nix::sys::termios::{self, LocalFlags, OutputFlags, Termios, tcgetattr};
use nix::unistd::{read, write, close};
/// Helper function analogous to std::io::Write::write_all, but for `RawFd`s
@@ -61,11 +61,11 @@ fn test_output_flags() {
};
// Make sure postprocessing '\r' isn't specified by default or this test is useless.
- assert!(!termios.output_flags.contains(OPOST | OCRNL));
+ assert!(!termios.output_flags.contains(OutputFlags::OPOST | OutputFlags::OCRNL));
// Specify that '\r' characters should be transformed to '\n'
// OPOST is specified to enable post-processing
- termios.output_flags.insert(OPOST | OCRNL);
+ termios.output_flags.insert(OutputFlags::OPOST | OutputFlags::OCRNL);
// Open a pty
let pty = openpty(None, &termios).unwrap();
@@ -104,10 +104,10 @@ fn test_local_flags() {
};
// Make sure echo is specified by default or this test is useless.
- assert!(termios.local_flags.contains(ECHO));
+ assert!(termios.local_flags.contains(LocalFlags::ECHO));
// Disable local echo
- termios.local_flags.remove(ECHO);
+ termios.local_flags.remove(LocalFlags::ECHO);
// Open a new pty with our modified termios settings
let pty = openpty(None, &termios).unwrap();
@@ -116,7 +116,7 @@ fn test_local_flags() {
// Set the master is in nonblocking mode or reading will never return.
let flags = fcntl::fcntl(pty.master, fcntl::F_GETFL).unwrap();
- let new_flags = fcntl::OFlag::from_bits_truncate(flags) | fcntl::O_NONBLOCK;
+ let new_flags = fcntl::OFlag::from_bits_truncate(flags) | fcntl::OFlag::O_NONBLOCK;
fcntl::fcntl(pty.master, fcntl::F_SETFL(new_flags)).unwrap();
// Write into the master
diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs
index 57296938..a2b68d07 100644
--- a/test/sys/test_uio.rs
+++ b/test/sys/test_uio.rs
@@ -199,7 +199,6 @@ fn test_process_vm_readv() {
use nix::unistd::ForkResult::*;
use nix::sys::signal::*;
use nix::sys::wait::*;
- use std::str;
#[allow(unused_variables)]
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 0fcaa19c..44a111a3 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -54,8 +54,7 @@ fn test_waitstatus_pid() {
// FIXME: qemu-user doesn't implement ptrace on most arches
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod ptrace {
- use nix::sys::ptrace;
- use nix::sys::ptrace::*;
+ use nix::sys::ptrace::{self, Options, Event};
use nix::sys::signal::*;
use nix::sys::wait::*;
use nix::unistd::*;
@@ -74,7 +73,7 @@ mod ptrace {
// Wait for the raised SIGTRAP
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, SIGTRAP)));
// We want to test a syscall stop and a PTRACE_EVENT stop
- assert!(ptrace::setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok());
+ assert!(ptrace::setoptions(child, Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT).is_ok());
// First, stop on the next system call, which will be exit()
assert!(ptrace::syscall(child).is_ok());
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index d171b91d..795b6c85 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -1,4 +1,4 @@
-use nix::fcntl::{openat, open, OFlag, O_RDONLY, readlink, readlinkat};
+use nix::fcntl::{openat, open, OFlag, readlink, readlinkat};
use nix::sys::stat::Mode;
use nix::unistd::{close, read};
use tempdir::TempDir;
@@ -17,7 +17,7 @@ fn test_openat() {
Mode::empty()).unwrap();
let fd = openat(dirfd,
tmp.path().file_name().unwrap(),
- O_RDONLY,
+ OFlag::O_RDONLY,
Mode::empty()).unwrap();
let mut buf = [0u8; 1024];
diff --git a/test/test_mount.rs b/test/test_mount.rs
index 57ff2106..e4cd6ba7 100644
--- a/test/test_mount.rs
+++ b/test/test_mount.rs
@@ -18,9 +18,9 @@ mod test_mount {
use libc::{EACCES, EROFS};
use nix::errno::Errno;
- use nix::mount::{mount, umount, MsFlags, MS_BIND, MS_RDONLY, MS_NOEXEC};
- use nix::sched::{unshare, CLONE_NEWNS, CLONE_NEWUSER};
- use nix::sys::stat::{self, S_IRWXU, S_IRWXG, S_IRWXO, S_IXUSR, S_IXGRP, S_IXOTH};
+ use nix::mount::{mount, umount, MsFlags};
+ use nix::sched::{unshare, CloneFlags};
+ use nix::sys::stat::{self, Mode};
use nix::unistd::getuid;
use tempdir::TempDir;
@@ -48,7 +48,7 @@ exit 23";
fs::OpenOptions::new()
.create(true)
.write(true)
- .mode((S_IRWXU | S_IRWXG | S_IRWXO).bits())
+ .mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits())
.open(&test_path)
.or_else(|e|
if Errno::from_i32(e.raw_os_error().unwrap()) == Errno::EOVERFLOW {
@@ -95,7 +95,7 @@ exit 23";
mount(NONE,
tempdir.path(),
Some(b"tmpfs".as_ref()),
- MS_RDONLY,
+ MsFlags::MS_RDONLY,
NONE)
.unwrap_or_else(|e| panic!("mount failed: {}", e));
@@ -113,7 +113,7 @@ exit 23";
mount(NONE,
tempdir.path(),
Some(b"tmpfs".as_ref()),
- MS_NOEXEC,
+ MsFlags::MS_NOEXEC,
NONE)
.unwrap_or_else(|e| panic!("mount failed: {}", e));
@@ -122,7 +122,7 @@ exit 23";
fs::OpenOptions::new()
.create(true)
.write(true)
- .mode((S_IRWXU | S_IRWXG | S_IRWXO).bits())
+ .mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits())
.open(&test_path)
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
.unwrap_or_else(|e| panic!("write failed: {}", e));
@@ -134,7 +134,7 @@ exit 23";
panic!("metadata failed: {}", e)
}));
- assert!(mode.contains(S_IXUSR | S_IXGRP | S_IXOTH),
+ assert!(mode.contains(Mode::S_IXUSR | Mode::S_IXGRP | Mode::S_IXOTH),
"{:?} did not have execute permissions",
&test_path);
@@ -157,14 +157,14 @@ exit 23";
mount(Some(tempdir.path()),
mount_point.path(),
NONE,
- MS_BIND,
+ MsFlags::MS_BIND,
NONE)
.unwrap_or_else(|e| panic!("mount failed: {}", e));
fs::OpenOptions::new()
.create(true)
.write(true)
- .mode((S_IRWXU | S_IRWXG | S_IRWXO).bits())
+ .mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits())
.open(mount_point.path().join(file_name))
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
.unwrap_or_else(|e| panic!("write failed: {}", e));
@@ -186,7 +186,7 @@ exit 23";
// Hold on to the uid in the parent namespace.
let uid = getuid();
- unshare(CLONE_NEWNS | CLONE_NEWUSER).unwrap_or_else(|e| {
+ unshare(CloneFlags::CLONE_NEWNS | CloneFlags::CLONE_NEWUSER).unwrap_or_else(|e| {
let stderr = io::stderr();
let mut handle = stderr.lock();
writeln!(handle,
diff --git a/test/test_mq.rs b/test/test_mq.rs
index 39e6b62a..bf32696c 100644
--- a/test/test_mq.rs
+++ b/test/test_mq.rs
@@ -1,15 +1,13 @@
-use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_getattr, mq_setattr, mq_unlink, mq_set_nonblock, mq_remove_nonblock};
-use nix::mqueue::{O_CREAT, O_WRONLY, O_RDONLY, O_NONBLOCK};
-
+use libc::c_long;
-use nix::mqueue::MqAttr;
-use nix::sys::stat::{S_IWUSR, S_IRUSR, S_IRGRP, S_IROTH};
use std::ffi::CString;
use std::str;
-use libc::c_long;
use nix::errno::Errno::*;
use nix::Error::Sys;
+use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_getattr, mq_setattr, mq_unlink, mq_set_nonblock, mq_remove_nonblock};
+use nix::mqueue::{MqAttr, MQ_OFlag};
+use nix::sys::stat::Mode;
#[test]
fn test_mq_send_and_receive() {
@@ -17,14 +15,14 @@ fn test_mq_send_and_receive() {
let attr = MqAttr::new(0, 10, MSG_SIZE, 0);
let mq_name= &CString::new(b"/a_nix_test_queue".as_ref()).unwrap();
- let mqd0 = mq_open(mq_name, O_CREAT | O_WRONLY,
- S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
+ let mqd0 = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY,
+ Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH,
Some(&attr)).unwrap();
let msg_to_send = "msg_1";
mq_send(mqd0, msg_to_send.as_bytes(), 1).unwrap();
- let mqd1 = mq_open(mq_name, O_CREAT | O_RDONLY,
- S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
+ let mqd1 = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_RDONLY,
+ Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH,
Some(&attr)).unwrap();
let mut buf = [0u8; 32];
let mut prio = 0u32;
@@ -42,7 +40,7 @@ fn test_mq_getattr() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap();
- let mqd = mq_open(mq_name, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap();
+ let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
let read_attr = mq_getattr(mqd);
assert!(read_attr.unwrap() == initial_attr);
mq_close(mqd).unwrap();
@@ -55,7 +53,7 @@ fn test_mq_setattr() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap();
- let mqd = mq_open(mq_name, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap();
+ let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
let new_attr = MqAttr::new(0, 20, MSG_SIZE * 2, 100);
let old_attr = mq_setattr(mqd, &new_attr);
@@ -66,7 +64,7 @@ fn test_mq_setattr() {
// O_NONBLOCK can be set (see tests below)
assert!(new_attr_get.unwrap() != new_attr);
- let new_attr_non_blocking = MqAttr::new(O_NONBLOCK.bits() as c_long, 10, MSG_SIZE, 0);
+ let new_attr_non_blocking = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long, 10, MSG_SIZE, 0);
mq_setattr(mqd, &new_attr_non_blocking).unwrap();
let new_attr_get = mq_getattr(mqd);
@@ -83,10 +81,10 @@ fn test_mq_set_nonblocking() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap();
- let mqd = mq_open(mq_name, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap();
+ let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
mq_set_nonblock(mqd).unwrap();
let new_attr = mq_getattr(mqd);
- assert!(new_attr.unwrap().flags() == O_NONBLOCK.bits() as c_long);
+ assert!(new_attr.unwrap().flags() == MQ_OFlag::O_NONBLOCK.bits() as c_long);
mq_remove_nonblock(mqd).unwrap();
let new_attr = mq_getattr(mqd);
assert!(new_attr.unwrap().flags() == 0);
@@ -99,7 +97,7 @@ fn test_mq_unlink() {
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
let mq_name_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap();
let mq_name_not_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap();
- let mqd = mq_open(mq_name_opened, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap();
+ let mqd = mq_open(mq_name_opened, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
let res_unlink = mq_unlink(mq_name_opened);
assert!(res_unlink == Ok(()) );
diff --git a/test/test_poll.rs b/test/test_poll.rs
index a48604f9..c28c8fd8 100644
--- a/test/test_poll.rs
+++ b/test/test_poll.rs
@@ -1,4 +1,4 @@
-use nix::poll::*;
+use nix::poll::{EventFlags, poll, PollFd};
use nix::sys::signal::SigSet;
use nix::sys::time::{TimeSpec, TimeValLike};
use nix::unistd::{write, pipe};
@@ -6,19 +6,19 @@ use nix::unistd::{write, pipe};
#[test]
fn test_poll() {
let (r, w) = pipe().unwrap();
- let mut fds = [PollFd::new(r, POLLIN)];
+ let mut fds = [PollFd::new(r, EventFlags::POLLIN)];
// Poll an idle pipe. Should timeout
let nfds = poll(&mut fds, 100).unwrap();
assert_eq!(nfds, 0);
- assert!(!fds[0].revents().unwrap().contains(POLLIN));
+ assert!(!fds[0].revents().unwrap().contains(EventFlags::POLLIN));
write(w, b".").unwrap();
// Poll a readable pipe. Should return an event.
let nfds = poll(&mut fds, 100).unwrap();
assert_eq!(nfds, 1);
- assert!(fds[0].revents().unwrap().contains(POLLIN));
+ assert!(fds[0].revents().unwrap().contains(EventFlags::POLLIN));
}
// ppoll(2) is the same as poll except for how it handles timeouts and signals.
@@ -30,19 +30,20 @@ fn test_poll() {
target_os = "linux"))]
#[test]
fn test_ppoll() {
+ use nix::poll::ppoll;
let timeout = TimeSpec::milliseconds(1);
let (r, w) = pipe().unwrap();
- let mut fds = [PollFd::new(r, POLLIN)];
+ let mut fds = [PollFd::new(r, EventFlags::POLLIN)];
// Poll an idle pipe. Should timeout
let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
assert_eq!(nfds, 0);
- assert!(!fds[0].revents().unwrap().contains(POLLIN));
+ assert!(!fds[0].revents().unwrap().contains(EventFlags::POLLIN));
write(w, b".").unwrap();
// Poll a readable pipe. Should return an event.
let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
assert_eq!(nfds, 1);
- assert!(fds[0].revents().unwrap().contains(POLLIN));
+ assert!(fds[0].revents().unwrap().contains(EventFlags::POLLIN));
}
diff --git a/test/test_pty.rs b/test/test_pty.rs
index 89706f0c..7104a9a5 100644
--- a/test/test_pty.rs
+++ b/test/test_pty.rs
@@ -3,7 +3,7 @@ use std::path::Path;
use std::os::unix::prelude::*;
use tempfile::tempfile;
-use nix::fcntl::{O_RDWR, open};
+use nix::fcntl::{OFlag, open};
use nix::pty::*;
use nix::sys::stat;
use nix::sys::termios::*;
@@ -14,7 +14,7 @@ use nix::unistd::{write, close};
#[test]
fn test_explicit_close() {
let mut f = {
- let m = posix_openpt(O_RDWR).unwrap();
+ let m = posix_openpt(OFlag::O_RDWR).unwrap();
close(m.into_raw_fd()).unwrap();
tempfile().unwrap()
};
@@ -31,7 +31,7 @@ fn test_ptsname_equivalence() {
let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
// Open a new PTTY master
- let master_fd = posix_openpt(O_RDWR).unwrap();
+ let master_fd = posix_openpt(OFlag::O_RDWR).unwrap();
assert!(master_fd.as_raw_fd() > 0);
// Get the name of the slave
@@ -49,7 +49,7 @@ fn test_ptsname_copy() {
let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
// Open a new PTTY master
- let master_fd = posix_openpt(O_RDWR).unwrap();
+ let master_fd = posix_openpt(OFlag::O_RDWR).unwrap();
assert!(master_fd.as_raw_fd() > 0);
// Get the name of the slave
@@ -66,7 +66,7 @@ fn test_ptsname_copy() {
#[cfg(any(target_os = "android", target_os = "linux"))]
fn test_ptsname_r_copy() {
// Open a new PTTY master
- let master_fd = posix_openpt(O_RDWR).unwrap();
+ let master_fd = posix_openpt(OFlag::O_RDWR).unwrap();
assert!(master_fd.as_raw_fd() > 0);
// Get the name of the slave
@@ -84,11 +84,11 @@ fn test_ptsname_unique() {
let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
// Open a new PTTY master
- let master1_fd = posix_openpt(O_RDWR).unwrap();
+ let master1_fd = posix_openpt(OFlag::O_RDWR).unwrap();
assert!(master1_fd.as_raw_fd() > 0);
// Open a second PTTY master
- let master2_fd = posix_openpt(O_RDWR).unwrap();
+ let master2_fd = posix_openpt(OFlag::O_RDWR).unwrap();
assert!(master2_fd.as_raw_fd() > 0);
// Get the name of the slave
@@ -108,7 +108,7 @@ fn test_open_ptty_pair() {
let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
// Open a new PTTY master
- let master_fd = posix_openpt(O_RDWR).expect("posix_openpt failed");
+ let master_fd = posix_openpt(OFlag::O_RDWR).expect("posix_openpt failed");
assert!(master_fd.as_raw_fd() > 0);
// Allow a slave to be generated for it
@@ -119,7 +119,7 @@ fn test_open_ptty_pair() {
let slave_name = unsafe { ptsname(&master_fd) }.expect("ptsname failed");
// Open the slave device
- let slave_fd = open(Path::new(&slave_name), O_RDWR, stat::Mode::empty()).unwrap();
+ let slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty()).unwrap();
assert!(slave_fd > 0);
}
@@ -176,7 +176,7 @@ fn test_openpty_with_termios() {
termios
};
// Make sure newlines are not transformed so the data is preserved when sent.
- termios.output_flags.remove(ONLCR);
+ termios.output_flags.remove(OutputFlags::ONLCR);
let pty = openpty(None, &termios).unwrap();
// Must be valid file descriptors
diff --git a/test/test_ptymaster_drop.rs b/test/test_ptymaster_drop.rs
index 664a4dd6..bde8510c 100644
--- a/test/test_ptymaster_drop.rs
+++ b/test/test_ptymaster_drop.rs
@@ -1,6 +1,6 @@
extern crate nix;
-use nix::fcntl::O_RDWR;
+use nix::fcntl::OFlag;
use nix::pty::*;
use nix::unistd::close;
use std::os::unix::io::AsRawFd;
@@ -15,7 +15,7 @@ use std::os::unix::io::AsRawFd;
// 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(O_RDWR).unwrap();
+ let m = posix_openpt(OFlag::O_RDWR).unwrap();
close(m.as_raw_fd()).unwrap();
drop(m); // should panic here
}
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 442c5921..b29ece3e 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -1,10 +1,9 @@
extern crate tempdir;
-use nix::fcntl;
use nix::unistd::*;
use nix::unistd::ForkResult::*;
use nix::sys::wait::*;
-use nix::sys::stat;
+use nix::sys::stat::{self, Mode, SFlag};
use std::{self, env, iter};
use std::ffi::CString;
use std::fs::File;
@@ -91,17 +90,17 @@ fn test_mkfifo() {
let tempdir = TempDir::new("nix-test_mkfifo").unwrap();
let mkfifo_fifo = tempdir.path().join("mkfifo_fifo");
- mkfifo(&mkfifo_fifo, stat::S_IRUSR).unwrap();
+ mkfifo(&mkfifo_fifo, Mode::S_IRUSR).unwrap();
let stats = stat::stat(&mkfifo_fifo).unwrap();
let typ = stat::SFlag::from_bits_truncate(stats.st_mode);
- assert!(typ == stat::S_IFIFO);
+ assert!(typ == SFlag::S_IFIFO);
}
#[test]
fn test_mkfifo_directory() {
// mkfifo should fail if a directory is given
- assert!(mkfifo(&env::temp_dir(), stat::S_IRUSR).is_err());
+ assert!(mkfifo(&env::temp_dir(), Mode::S_IRUSR).is_err());
}
#[test]
@@ -257,19 +256,21 @@ cfg_if!{
cfg_if!{
if #[cfg(target_os = "android")] {
+ use nix::fcntl::AtFlags;
execve_test_factory!(test_execveat_empty, execveat, File::open("/system/bin/sh").unwrap().into_raw_fd(),
- "", fcntl::AT_EMPTY_PATH);
+ "", AtFlags::AT_EMPTY_PATH);
execve_test_factory!(test_execveat_relative, execveat, File::open("/system/bin/").unwrap().into_raw_fd(),
- "./sh", fcntl::AtFlags::empty());
+ "./sh", AtFlags::empty());
execve_test_factory!(test_execveat_absolute, execveat, File::open("/").unwrap().into_raw_fd(),
- "/system/bin/sh", fcntl::AtFlags::empty());
+ "/system/bin/sh", AtFlags::empty());
} else if #[cfg(all(target_os = "linux"), any(target_arch ="x86_64", target_arch ="x86"))] {
+ use nix::fcntl::AtFlags;
execve_test_factory!(test_execveat_empty, execveat, File::open("/bin/sh").unwrap().into_raw_fd(),
- "", fcntl::AT_EMPTY_PATH);
+ "", AtFlags::AT_EMPTY_PATH);
execve_test_factory!(test_execveat_relative, execveat, File::open("/bin/").unwrap().into_raw_fd(),
- "./sh", fcntl::AtFlags::empty());
+ "./sh", AtFlags::empty());
execve_test_factory!(test_execveat_absolute, execveat, File::open("/").unwrap().into_raw_fd(),
- "/bin/sh", fcntl::AtFlags::empty());
+ "/bin/sh", AtFlags::empty());
}
}
@@ -308,7 +309,7 @@ fn test_getcwd() {
for _ in 0..5 {
let newdir = iter::repeat("a").take(100).collect::<String>();
inner_tmp_dir.push(newdir);
- assert!(mkdir(inner_tmp_dir.as_path(), stat::S_IRWXU).is_ok());
+ assert!(mkdir(inner_tmp_dir.as_path(), Mode::S_IRWXU).is_ok());
}
assert!(chdir(inner_tmp_dir.as_path()).is_ok());
assert_eq!(getcwd().unwrap(), inner_tmp_dir.as_path());