From e1baab9dc132f18e13f446df0271a5e46723848d Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Tue, 21 Nov 2017 22:27:15 -0800 Subject: 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. --- src/sys/event.rs | 4 ++-- src/sys/quota.rs | 20 ++++++++++---------- src/sys/signal.rs | 10 +++++----- src/sys/signalfd.rs | 6 +++--- src/sys/socket/mod.rs | 34 +++++++++++++++++----------------- src/sys/termios.rs | 6 +++--- 6 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src/sys') 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { /// 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>>(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>>(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 { 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}; -- cgit v1.2.3