From d458ecd4e1205d36230ecac85c67472e3227a92d Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Tue, 9 Aug 2022 12:15:52 +0800 Subject: [PATCH 1/4] remove deprecated items --- src/sched.rs | 4 +- src/sys/personality.rs | 2 +- src/sys/quota.rs | 4 +- src/sys/socket/mod.rs | 2 +- src/sys/socket/sockopt.rs | 2 +- src/sys/termios.rs | 10 +- src/sys/time.rs | 62 +++++------ src/unistd.rs | 66 ++++++------ test/sys/test_pthread.rs | 2 +- test/sys/test_ptrace.rs | 52 ++++----- test/test_dir.rs | 2 +- test/test_pty.rs | 6 +- test/test_stat.rs | 66 ++++++------ test/test_unistd.rs | 216 +++++++++++++++++++------------------- 14 files changed, 248 insertions(+), 248 deletions(-) diff --git a/src/sched.rs b/src/sched.rs index e736f8d249..e9a326e261 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -233,8 +233,8 @@ mod sched_affinity { /// use nix::unistd::Pid; /// /// let mut cpu_set = CpuSet::new(); - /// cpu_set.set(0); - /// sched_setaffinity(Pid::from_raw(0), &cpu_set); + /// cpu_set.set(0).unwrap(); + /// sched_setaffinity(Pid::from_raw(0), &cpu_set).unwrap(); /// ``` pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> { let res = unsafe { diff --git a/src/sys/personality.rs b/src/sys/personality.rs index 2af6687823..15b59017be 100644 --- a/src/sys/personality.rs +++ b/src/sys/personality.rs @@ -86,7 +86,7 @@ pub fn get() -> Result { /// # use nix::sys::personality::{self, Persona}; /// let mut pers = personality::get().unwrap(); /// assert!(!pers.contains(Persona::ADDR_NO_RANDOMIZE)); -/// personality::set(pers | Persona::ADDR_NO_RANDOMIZE); +/// personality::set(pers | Persona::ADDR_NO_RANDOMIZE).unwrap().unwrap(); /// ``` pub fn set(persona: Persona) -> Result { let res = unsafe { diff --git a/src/sys/quota.rs b/src/sys/quota.rs index 6e34e38d2b..f3b4c02dee 100644 --- a/src/sys/quota.rs +++ b/src/sys/quota.rs @@ -6,11 +6,11 @@ //! //! ```rust,no_run //! # use nix::sys::quota::{Dqblk, quotactl_on, quotactl_set, QuotaFmt, QuotaType, QuotaValidFlags}; -//! quotactl_on(QuotaType::USRQUOTA, "/dev/sda1", QuotaFmt::QFMT_VFS_V1, "aquota.user"); +//! quotactl_on(QuotaType::USRQUOTA, "/dev/sda1", QuotaFmt::QFMT_VFS_V1, "aquota.user").unwrap(); //! 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, QuotaValidFlags::QIF_BLIMITS); +//! quotactl_set(QuotaType::USRQUOTA, "/dev/sda1", 50, &dqblk, QuotaValidFlags::QIF_BLIMITS).unwrap(); //! ``` use std::default::Default; use std::{mem, ptr}; diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 2dfa8ec6e6..7e6d60948e 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -677,7 +677,7 @@ pub enum ControlMessageOwned { /// None).unwrap(); /// setsockopt(in_socket, sockopt::ReceiveTimestamp, &true).unwrap(); /// let localhost = SockaddrIn::from_str("127.0.0.1:0").unwrap(); - /// bind(in_socket, &localhost); + /// bind(in_socket, &localhost).unwrap(); /// let address: SockaddrIn = getsockname(in_socket).unwrap(); /// // Get initial time /// let time0 = SystemTime::now(); diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index fff496dbbd..1cbb223ece 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -982,7 +982,7 @@ mod test { let a_cred = getsockopt(a, super::PeerCredentials).unwrap(); let b_cred = getsockopt(b, super::PeerCredentials).unwrap(); assert_eq!(a_cred, b_cred); - assert!(a_cred.pid() != 0); + assert_ne!(a_cred.pid(), 0); } #[test] diff --git a/src/sys/termios.rs b/src/sys/termios.rs index feb52c0ab9..c5b27d28ea 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -64,9 +64,9 @@ //! # use nix::sys::termios::{BaudRate, cfsetispeed, cfsetospeed, cfsetspeed, Termios}; //! # fn main() { //! # let mut t: Termios = unsafe { std::mem::zeroed() }; -//! cfsetispeed(&mut t, BaudRate::B9600); -//! cfsetospeed(&mut t, BaudRate::B9600); -//! cfsetspeed(&mut t, BaudRate::B9600); +//! cfsetispeed(&mut t, BaudRate::B9600).unwrap(); +//! cfsetospeed(&mut t, BaudRate::B9600).unwrap(); +//! cfsetspeed(&mut t, BaudRate::B9600).unwrap(); //! # } //! ``` //! @@ -76,10 +76,10 @@ //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetispeed, cfsetspeed, Termios}; //! # fn main() { //! # let mut t: Termios = unsafe { std::mem::zeroed() }; -//! # cfsetspeed(&mut t, BaudRate::B9600); +//! # cfsetspeed(&mut t, BaudRate::B9600).unwrap(); //! let speed = cfgetispeed(&t); //! assert_eq!(speed, cfgetospeed(&t)); -//! cfsetispeed(&mut t, speed); +//! cfsetispeed(&mut t, speed).unwrap(); //! # } //! ``` //! diff --git a/src/sys/time.rs b/src/sys/time.rs index b7ab3986f8..3627997855 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -7,17 +7,17 @@ use std::time::Duration; use std::{cmp, fmt, ops}; #[cfg(any( - all(feature = "time", any(target_os = "android", target_os = "linux")), - all( - any( - target_os = "freebsd", - target_os = "illumos", - target_os = "linux", - target_os = "netbsd" - ), - feature = "time", - feature = "signal" - ) +all(feature = "time", any(target_os = "android", target_os = "linux")), +all( +any( +target_os = "freebsd", +target_os = "illumos", +target_os = "linux", +target_os = "netbsd" +), +feature = "time", +feature = "signal" +) ))] pub(crate) mod timer { use crate::sys::time::TimeSpec; @@ -98,10 +98,10 @@ pub(crate) mod timer { } } #[cfg(any( - target_os = "freebsd", - target_os = "netbsd", - target_os = "dragonfly", - target_os = "illumos" + target_os = "freebsd", + target_os = "netbsd", + target_os = "dragonfly", + target_os = "illumos" ))] bitflags! { /// Flags that are used for arming the timer. @@ -114,17 +114,17 @@ pub(crate) mod timer { fn from(timerspec: TimerSpec) -> Expiration { match timerspec { TimerSpec(libc::itimerspec { - it_interval: - libc::timespec { - tv_sec: 0, - tv_nsec: 0, - }, - it_value: ts, - }) => Expiration::OneShot(ts.into()), + it_interval: + libc::timespec { + tv_sec: 0, + tv_nsec: 0, + }, + it_value: ts, + }) => Expiration::OneShot(ts.into()), TimerSpec(libc::itimerspec { - it_interval: int_ts, - it_value: val_ts, - }) => { + it_interval: int_ts, + it_value: val_ts, + }) => { if (int_ts.tv_sec == val_ts.tv_sec) && (int_ts.tv_nsec == val_ts.tv_nsec) { @@ -193,7 +193,7 @@ const SECS_PER_MINUTE: i64 = 60; const SECS_PER_HOUR: i64 = 3600; #[cfg(target_pointer_width = "64")] -const TS_MAX_SECONDS: i64 = (::std::i64::MAX / NANOS_PER_SEC) - 1; +const TS_MAX_SECONDS: i64 = (i64::MAX / NANOS_PER_SEC) - 1; #[cfg(target_pointer_width = "32")] const TS_MAX_SECONDS: i64 = ::std::isize::MAX as i64; @@ -453,7 +453,7 @@ pub struct TimeVal(timeval); const MICROS_PER_SEC: i64 = 1_000_000; #[cfg(target_pointer_width = "64")] -const TV_MAX_SECONDS: i64 = (::std::i64::MAX / MICROS_PER_SEC) - 1; +const TV_MAX_SECONDS: i64 = (i64::MAX / MICROS_PER_SEC) - 1; #[cfg(target_pointer_width = "32")] const TV_MAX_SECONDS: i64 = ::std::isize::MAX as i64; @@ -713,7 +713,7 @@ mod test { #[test] pub fn test_timespec() { - assert!(TimeSpec::seconds(1) != TimeSpec::zero()); + assert_ne!(TimeSpec::seconds(1), TimeSpec::zero()); assert_eq!( TimeSpec::seconds(1) + TimeSpec::seconds(2), TimeSpec::seconds(3) @@ -743,7 +743,7 @@ mod test { #[test] pub fn test_timespec_ord() { - assert!(TimeSpec::seconds(1) == TimeSpec::nanoseconds(1_000_000_000)); + assert_eq!(TimeSpec::seconds(1), TimeSpec::nanoseconds(1_000_000_000)); assert!(TimeSpec::seconds(1) < TimeSpec::nanoseconds(1_000_000_001)); assert!(TimeSpec::seconds(1) > TimeSpec::nanoseconds(999_999_999)); assert!(TimeSpec::seconds(-1) < TimeSpec::nanoseconds(-999_999_999)); @@ -765,7 +765,7 @@ mod test { #[test] pub fn test_timeval() { - assert!(TimeVal::seconds(1) != TimeVal::zero()); + assert_ne!(TimeVal::seconds(1), TimeVal::zero()); assert_eq!( TimeVal::seconds(1) + TimeVal::seconds(2), TimeVal::seconds(3) @@ -778,7 +778,7 @@ mod test { #[test] pub fn test_timeval_ord() { - assert!(TimeVal::seconds(1) == TimeVal::microseconds(1_000_000)); + assert_eq!(TimeVal::seconds(1), TimeVal::microseconds(1_000_000)); assert!(TimeVal::seconds(1) < TimeVal::microseconds(1_000_001)); assert!(TimeVal::seconds(1) > TimeVal::microseconds(999_999)); assert!(TimeVal::seconds(-1) < TimeVal::microseconds(-999_999)); diff --git a/src/unistd.rs b/src/unistd.rs index 70a06b0286..69419d640e 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -7,15 +7,15 @@ use crate::fcntl::{at_rawfd, AtFlags}; #[cfg(feature = "fs")] use crate::fcntl::{fcntl, FcntlArg::F_SETFD, FdFlag, OFlag}; #[cfg(all( - feature = "fs", - any( - target_os = "openbsd", - target_os = "netbsd", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "macos", - target_os = "ios" - ) +feature = "fs", +any( +target_os = "openbsd", +target_os = "netbsd", +target_os = "freebsd", +target_os = "dragonfly", +target_os = "macos", +target_os = "ios" +) ))] use crate::sys::stat::FileFlag; #[cfg(feature = "fs")] @@ -45,20 +45,20 @@ feature! { } #[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" +target_os = "android", +target_os = "dragonfly", +target_os = "freebsd", +target_os = "linux", +target_os = "openbsd" ))] pub use self::setres::*; #[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" +target_os = "android", +target_os = "dragonfly", +target_os = "freebsd", +target_os = "linux", +target_os = "openbsd" ))] pub use self::getres::*; @@ -1572,7 +1572,7 @@ pub fn getgroups() -> Result> { /// # use std::error::Error; /// # use nix::unistd::*; /// # -/// # fn try_main() -> Result<(), Box> { +/// # fn try_main() -> Result<(), Box> { /// let uid = Uid::from_raw(33); /// let gid = Gid::from_raw(34); /// setgroups(&[gid])?; @@ -1698,7 +1698,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result> { /// # use std::ffi::CString; /// # use nix::unistd::*; /// # -/// # fn try_main() -> Result<(), Box> { +/// # fn try_main() -> Result<(), Box> { /// let user = CString::new("www-data").unwrap(); /// let uid = Uid::from_raw(33); /// let gid = Gid::from_raw(33); @@ -2752,11 +2752,11 @@ mod pivot_root { } #[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" +target_os = "android", +target_os = "dragonfly", +target_os = "freebsd", +target_os = "linux", +target_os = "openbsd" ))] mod setres { feature! { @@ -2801,11 +2801,11 @@ mod setres { } #[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" +target_os = "android", +target_os = "dragonfly", +target_os = "freebsd", +target_os = "linux", +target_os = "openbsd" ))] mod getres { feature! { @@ -3121,7 +3121,7 @@ impl User { /// use nix::unistd::{Uid, User}; /// // Returns an Result>, thus the double unwrap. /// let res = User::from_uid(Uid::from_raw(0)).unwrap().unwrap(); - /// assert!(res.name == "root"); + /// assert_eq!(res.name, "root"); /// ``` pub fn from_uid(uid: Uid) -> Result> { User::from_anything(|pwd, cbuf, cap, res| { @@ -3140,7 +3140,7 @@ impl User { /// use nix::unistd::User; /// // Returns an Result>, thus the double unwrap. /// let res = User::from_name("root").unwrap().unwrap(); - /// assert!(res.name == "root"); + /// assert_eq!(res.name, "root"); /// ``` pub fn from_name(name: &str) -> Result> { let name = CString::new(name).unwrap(); diff --git a/test/sys/test_pthread.rs b/test/sys/test_pthread.rs index 42a4aefaad..ce048bae60 100644 --- a/test/sys/test_pthread.rs +++ b/test/sys/test_pthread.rs @@ -11,7 +11,7 @@ fn test_pthread_self() { #[test] fn test_pthread_self() { let tid = pthread_self(); - assert!(tid != 0); + assert_ne!(tid, 0); } #[test] diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index e514832b82..1668058329 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -1,7 +1,7 @@ #[cfg(all( - target_os = "linux", - any(target_arch = "x86_64", target_arch = "x86"), - target_env = "gnu" +target_os = "linux", +any(target_arch = "x86_64", target_arch = "x86"), +target_env = "gnu" ))] use memoffset::offset_of; use nix::errno::Errno; @@ -33,7 +33,7 @@ fn test_ptrace_setoptions() { require_capability!("test_ptrace_setoptions", CAP_SYS_PTRACE); let err = ptrace::setoptions(getpid(), Options::PTRACE_O_TRACESYSGOOD) .unwrap_err(); - assert!(err != Errno::EOPNOTSUPP); + assert_ne!(err, Errno::EOPNOTSUPP); } // Just make sure ptrace_getevent can be called at all, for now. @@ -42,7 +42,7 @@ fn test_ptrace_setoptions() { fn test_ptrace_getevent() { require_capability!("test_ptrace_getevent", CAP_SYS_PTRACE); let err = ptrace::getevent(getpid()).unwrap_err(); - assert!(err != Errno::EOPNOTSUPP); + assert_ne!(err, Errno::EOPNOTSUPP); } // Just make sure ptrace_getsiginfo can be called at all, for now. @@ -111,17 +111,17 @@ fn test_ptrace_cont() { ptrace::cont(child, Some(Signal::SIGKILL)).unwrap(); match waitpid(child, None) { Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) - if pid == child => - { - // FIXME It's been observed on some systems (apple) the - // tracee may not be killed but remain as a zombie process - // affecting other wait based tests. Add an extra kill just - // to make sure there are no zombies. - let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); - while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { + if pid == child => + { + // FIXME It's been observed on some systems (apple) the + // tracee may not be killed but remain as a zombie process + // affecting other wait based tests. Add an extra kill just + // to make sure there are no zombies. let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { + let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + } } - } _ => panic!("The process should have been killed"), } } @@ -163,13 +163,13 @@ fn test_ptrace_interrupt() { ptrace::detach(child, Some(Signal::SIGKILL)).unwrap(); match waitpid(child, None) { Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) - if pid == child => - { - let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); - while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { + if pid == child => + { let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { + let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + } } - } _ => panic!("The process should have been killed"), } } @@ -178,9 +178,9 @@ fn test_ptrace_interrupt() { // ptrace::{setoptions, getregs} are only available in these platforms #[cfg(all( - target_os = "linux", - any(target_arch = "x86_64", target_arch = "x86"), - target_env = "gnu" +target_os = "linux", +any(target_arch = "x86_64", target_arch = "x86"), +target_env = "gnu" ))] #[test] fn test_ptrace_syscall() { @@ -219,18 +219,18 @@ fn test_ptrace_syscall() { .unwrap(); #[cfg(target_arch = "x86_64")] - let get_syscall_id = + let get_syscall_id = || ptrace::getregs(child).unwrap().orig_rax as libc::c_long; #[cfg(target_arch = "x86")] - let get_syscall_id = + let get_syscall_id = || ptrace::getregs(child).unwrap().orig_eax as libc::c_long; // this duplicates `get_syscall_id` for the purpose of testing `ptrace::read_user`. #[cfg(target_arch = "x86_64")] - let rax_offset = offset_of!(libc::user_regs_struct, orig_rax); + let rax_offset = offset_of!(libc::user_regs_struct, orig_rax); #[cfg(target_arch = "x86")] - let rax_offset = offset_of!(libc::user_regs_struct, orig_eax); + let rax_offset = offset_of!(libc::user_regs_struct, orig_eax); let get_syscall_from_user_area = || { // Find the offset of `user.regs.rax` (or `user.regs.eax` for x86) diff --git a/test/test_dir.rs b/test/test_dir.rs index 9d2780c0e6..f66299210e 100644 --- a/test/test_dir.rs +++ b/test/test_dir.rs @@ -20,7 +20,7 @@ fn flags() -> OFlag { fn read() { let tmp = tempdir().unwrap(); File::create(&tmp.path().join("foo")).unwrap(); - ::std::os::unix::fs::symlink("foo", tmp.path().join("bar")).unwrap(); + std::os::unix::fs::symlink("foo", tmp.path().join("bar")).unwrap(); let mut dir = Dir::open(tmp.path(), flags(), Mode::empty()).unwrap(); let mut entries: Vec<_> = dir.iter().map(|e| e.unwrap()).collect(); entries.sort_by(|a, b| a.file_name().cmp(b.file_name())); diff --git a/test/test_pty.rs b/test/test_pty.rs index 3b52289e5c..5c27e2d632 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -58,7 +58,7 @@ fn test_ptsname_copy() { assert_eq!(slave_name1, slave_name2); // Also make sure that the string was actually copied and they point to different parts of // memory. - assert!(slave_name1.as_ptr() != slave_name2.as_ptr()); + assert_ne!(slave_name1.as_ptr(), slave_name2.as_ptr()); } /// Test data copying of `ptsname_r` @@ -73,7 +73,7 @@ fn test_ptsname_r_copy() { let slave_name1 = ptsname_r(&master_fd).unwrap(); let slave_name2 = ptsname_r(&master_fd).unwrap(); assert_eq!(slave_name1, slave_name2); - assert!(slave_name1.as_ptr() != slave_name2.as_ptr()); + assert_ne!(slave_name1.as_ptr(), slave_name2.as_ptr()); } /// Test that `ptsname` returns different names for different devices @@ -93,7 +93,7 @@ fn test_ptsname_unique() { // Get the name of the slave let slave_name1 = unsafe { ptsname(&master1_fd) }.unwrap(); let slave_name2 = unsafe { ptsname(&master2_fd) }.unwrap(); - assert!(slave_name1 != slave_name2); + assert_ne!(slave_name1, slave_name2); } /// Common setup for testing PTTY pairs diff --git a/test/test_stat.rs b/test/test_stat.rs index 1888c64914..bed33b5456 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -20,11 +20,11 @@ use nix::errno::Errno; #[cfg(not(target_os = "redox"))] use nix::fcntl; #[cfg(any( - target_os = "linux", - target_os = "ios", - target_os = "macos", - target_os = "freebsd", - target_os = "netbsd" +target_os = "linux", +target_os = "ios", +target_os = "macos", +target_os = "freebsd", +target_os = "netbsd" ))] use nix::sys::stat::lutimes; #[cfg(not(any(target_os = "redox", target_os = "haiku")))] @@ -234,11 +234,11 @@ fn test_utimes() { #[test] #[cfg(any( - target_os = "linux", - target_os = "ios", - target_os = "macos", - target_os = "freebsd", - target_os = "netbsd" +target_os = "linux", +target_os = "ios", +target_os = "macos", +target_os = "freebsd", +target_os = "netbsd" ))] fn test_lutimes() { let tempdir = tempfile::tempdir().unwrap(); @@ -299,7 +299,7 @@ fn test_utimensat() { &TimeSpec::seconds(678), UtimensatFlags::FollowSymlink, ) - .unwrap(); + .unwrap(); assert_times_eq(12345, 678, &fs::metadata(&fullpath).unwrap()); chdir(tempdir.path()).unwrap(); @@ -311,7 +311,7 @@ fn test_utimensat() { &TimeSpec::seconds(800), UtimensatFlags::FollowSymlink, ) - .unwrap(); + .unwrap(); assert_times_eq(500, 800, &fs::metadata(&fullpath).unwrap()); } @@ -356,19 +356,19 @@ fn test_mkdirat_fail() { fcntl::OFlag::O_CREAT, stat::Mode::empty(), ) - .unwrap(); + .unwrap(); let result = mkdirat(dirfd, filename, Mode::S_IRWXU).unwrap_err(); assert_eq!(result, Errno::ENOTDIR); } #[test] #[cfg(not(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "haiku", - target_os = "redox" +target_os = "dragonfly", +target_os = "freebsd", +target_os = "ios", +target_os = "macos", +target_os = "haiku", +target_os = "redox" )))] fn test_mknod() { use stat::{lstat, mknod, SFlag}; @@ -378,19 +378,19 @@ fn test_mknod() { let target = tempdir.path().join(file_name); mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap(); let mode = lstat(&target).unwrap().st_mode as mode_t; - assert!(mode & libc::S_IFREG == libc::S_IFREG); - assert!(mode & libc::S_IRWXU == libc::S_IRWXU); + assert_eq!(mode & libc::S_IFREG, libc::S_IFREG); + assert_eq!(mode & libc::S_IRWXU, libc::S_IRWXU); } #[test] #[cfg(not(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "haiku", - target_os = "redox" +target_os = "dragonfly", +target_os = "freebsd", +target_os = "illumos", +target_os = "ios", +target_os = "macos", +target_os = "haiku", +target_os = "redox" )))] fn test_mknodat() { use fcntl::{AtFlags, OFlag}; @@ -408,14 +408,14 @@ fn test_mknodat() { Mode::S_IRWXU, 0, ) - .unwrap(); + .unwrap(); let mode = fstatat( target_dir.as_raw_fd(), file_name, AtFlags::AT_SYMLINK_NOFOLLOW, ) - .unwrap() - .st_mode as mode_t; - assert!(mode & libc::S_IFREG == libc::S_IFREG); - assert!(mode & libc::S_IRWXU == libc::S_IRWXU); + .unwrap() + .st_mode as mode_t; + assert_eq!(mode & libc::S_IFREG, libc::S_IFREG); + assert_eq!(mode & libc::S_IRWXU, libc::S_IRWXU); } diff --git a/test/test_unistd.rs b/test/test_unistd.rs index b08ab33257..e4750d4b16 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -6,9 +6,9 @@ use nix::fcntl::OFlag; #[cfg(not(target_os = "redox"))] use nix::fcntl::{self, open}; #[cfg(not(any( - target_os = "redox", - target_os = "fuchsia", - target_os = "haiku" +target_os = "redox", +target_os = "fuchsia", +target_os = "haiku" )))] use nix::pty::{grantpt, posix_openpt, ptsname, unlockpt}; #[cfg(not(target_os = "redox"))] @@ -28,9 +28,9 @@ use std::fs::{self, File}; use std::io::Write; use std::os::unix::prelude::*; #[cfg(not(any( - target_os = "fuchsia", - target_os = "redox", - target_os = "haiku" +target_os = "fuchsia", +target_os = "redox", +target_os = "haiku" )))] use std::path::Path; use tempfile::{tempdir, tempfile}; @@ -114,7 +114,7 @@ fn test_mkfifo() { let stats = stat::stat(&mkfifo_fifo).unwrap(); let typ = stat::SFlag::from_bits_truncate(stats.st_mode as mode_t); - assert!(typ == SFlag::S_IFIFO); + assert_eq!(typ, SFlag::S_IFIFO); } #[test] @@ -126,11 +126,11 @@ fn test_mkfifo_directory() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "android", - target_os = "redox", - target_os = "haiku" +target_os = "macos", +target_os = "ios", +target_os = "android", +target_os = "redox", +target_os = "haiku" )))] fn test_mkfifoat_none() { let _m = crate::CWD_LOCK.read(); @@ -147,11 +147,11 @@ fn test_mkfifoat_none() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "android", - target_os = "redox", - target_os = "haiku" +target_os = "macos", +target_os = "ios", +target_os = "android", +target_os = "redox", +target_os = "haiku" )))] fn test_mkfifoat() { use nix::fcntl; @@ -170,11 +170,11 @@ fn test_mkfifoat() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "android", - target_os = "redox", - target_os = "haiku" +target_os = "macos", +target_os = "ios", +target_os = "android", +target_os = "redox", +target_os = "haiku" )))] fn test_mkfifoat_directory_none() { let _m = crate::CWD_LOCK.read(); @@ -186,11 +186,11 @@ fn test_mkfifoat_directory_none() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "android", - target_os = "redox", - target_os = "haiku" +target_os = "macos", +target_os = "ios", +target_os = "android", +target_os = "redox", +target_os = "haiku" )))] fn test_mkfifoat_directory() { // mkfifoat should fail if a directory is given @@ -234,11 +234,11 @@ mod linux_android { #[test] // `getgroups()` and `setgroups()` do not behave as expected on Apple platforms #[cfg(not(any( - target_os = "ios", - target_os = "macos", - target_os = "redox", - target_os = "fuchsia", - target_os = "haiku" +target_os = "ios", +target_os = "macos", +target_os = "redox", +target_os = "fuchsia", +target_os = "haiku" )))] fn test_setgroups() { // Skip this test when not run as root as `setgroups()` requires root. @@ -263,12 +263,12 @@ fn test_setgroups() { #[test] // `getgroups()` and `setgroups()` do not behave as expected on Apple platforms #[cfg(not(any( - target_os = "ios", - target_os = "macos", - target_os = "redox", - target_os = "fuchsia", - target_os = "haiku", - target_os = "illumos" +target_os = "ios", +target_os = "macos", +target_os = "redox", +target_os = "fuchsia", +target_os = "haiku", +target_os = "illumos" )))] fn test_initgroups() { // Skip this test when not run as root as `initgroups()` and `setgroups()` @@ -300,7 +300,7 @@ fn test_initgroups() { } #[cfg(not(any(target_os = "fuchsia", target_os = "redox")))] -macro_rules! execve_test_factory( +macro_rules! execve_test_factory ( ($test_name:ident, $syscall:ident, $exe: expr $(, $pathname:expr, $flags:expr)*) => ( #[cfg(test)] @@ -609,9 +609,9 @@ cfg_if! { #[test] #[cfg(not(any( - target_os = "redox", - target_os = "fuchsia", - target_os = "haiku" +target_os = "redox", +target_os = "fuchsia", +target_os = "haiku" )))] fn test_acct() { use std::process::Command; @@ -685,33 +685,33 @@ fn test_sysconf_unsupported() { } #[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" +target_os = "android", +target_os = "dragonfly", +target_os = "freebsd", +target_os = "linux", +target_os = "openbsd" ))] #[test] fn test_getresuid() { let resuids = getresuid().unwrap(); - assert!(resuids.real.as_raw() != libc::uid_t::max_value()); - assert!(resuids.effective.as_raw() != libc::uid_t::max_value()); - assert!(resuids.saved.as_raw() != libc::uid_t::max_value()); + assert_ne!(resuids.real.as_raw(), libc::uid_t::MAX); + assert_ne!(resuids.effective.as_raw(), libc::uid_t::MAX); + assert_ne!(resuids.saved.as_raw(), libc::uid_t::MAX); } #[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" +target_os = "android", +target_os = "dragonfly", +target_os = "freebsd", +target_os = "linux", +target_os = "openbsd" ))] #[test] fn test_getresgid() { let resgids = getresgid().unwrap(); - assert!(resgids.real.as_raw() != libc::gid_t::max_value()); - assert!(resgids.effective.as_raw() != libc::gid_t::max_value()); - assert!(resgids.saved.as_raw() != libc::gid_t::max_value()); + assert_ne!(resgids.real.as_raw(), libc::gid_t::MAX); + assert_ne!(resgids.effective.as_raw(), libc::gid_t::MAX); + assert_ne!(resgids.saved.as_raw(), libc::gid_t::MAX); } // Test that we can create a pair of pipes. No need to verify that they pass @@ -733,16 +733,16 @@ fn test_pipe() { // pipe2(2) is the same as pipe(2), except it allows setting some flags. Check // that we can set a flag. #[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "emscripten", - target_os = "freebsd", - target_os = "illumos", - target_os = "linux", - target_os = "netbsd", - target_os = "openbsd", - target_os = "redox", - target_os = "solaris" +target_os = "android", +target_os = "dragonfly", +target_os = "emscripten", +target_os = "freebsd", +target_os = "illumos", +target_os = "linux", +target_os = "netbsd", +target_os = "openbsd", +target_os = "redox", +target_os = "solaris" ))] #[test] fn test_pipe2() { @@ -918,7 +918,7 @@ fn test_linkat_file() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); assert!(newfilepath.exists()); } @@ -944,7 +944,7 @@ fn test_linkat_olddirfd_none() { fcntl::OFlag::empty(), stat::Mode::empty(), ) - .unwrap(); + .unwrap(); // Attempt hard link file using curent working directory as relative path for old file path chdir(tempdir_oldfile.path()).unwrap(); @@ -955,7 +955,7 @@ fn test_linkat_olddirfd_none() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); assert!(newfilepath.exists()); } @@ -981,7 +981,7 @@ fn test_linkat_newdirfd_none() { fcntl::OFlag::empty(), stat::Mode::empty(), ) - .unwrap(); + .unwrap(); // Attempt hard link file using current working directory as relative path for new file path chdir(tempdir_newfile.path()).unwrap(); @@ -992,16 +992,16 @@ fn test_linkat_newdirfd_none() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); assert!(newfilepath.exists()); } #[test] #[cfg(not(any( - target_os = "ios", - target_os = "macos", - target_os = "redox", - target_os = "haiku" +target_os = "ios", +target_os = "macos", +target_os = "redox", +target_os = "haiku" )))] fn test_linkat_no_follow_symlink() { let _m = crate::CWD_LOCK.read(); @@ -1035,7 +1035,7 @@ fn test_linkat_no_follow_symlink() { newfilename, LinkatFlags::NoSymlinkFollow, ) - .unwrap(); + .unwrap(); // Assert newfile is actually a symlink to oldfile. assert_eq!( @@ -1078,7 +1078,7 @@ fn test_linkat_follow_symlink() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); let newfilestat = stat::stat(&newfilepath).unwrap(); @@ -1180,10 +1180,10 @@ fn test_access_file_exists() { fn test_user_into_passwd() { // get the UID of the "nobody" user #[cfg(not(target_os = "haiku"))] - let test_username = "nobody"; + let test_username = "nobody"; // "nobody" unavailable on haiku #[cfg(target_os = "haiku")] - let test_username = "user"; + let test_username = "user"; let nobody = User::from_name(test_username).unwrap().unwrap(); let pwd: libc::passwd = nobody.into(); @@ -1221,8 +1221,8 @@ fn test_setfsuid() { let prev_fuid = setfsuid(Uid::from_raw(-1i32 as u32)); assert_ne!(prev_fuid, fuid); }) - .join() - .unwrap(); + .join() + .unwrap(); // open the temporary file with the current thread filesystem UID fs::File::open(temp_path_2).unwrap(); @@ -1230,9 +1230,9 @@ fn test_setfsuid() { #[test] #[cfg(not(any( - target_os = "redox", - target_os = "fuchsia", - target_os = "haiku" +target_os = "redox", +target_os = "fuchsia", +target_os = "haiku" )))] fn test_ttyname() { let fd = posix_openpt(OFlag::O_RDWR).expect("posix_openpt failed"); @@ -1262,9 +1262,9 @@ fn test_ttyname_not_pty() { #[test] #[cfg(not(any( - target_os = "redox", - target_os = "fuchsia", - target_os = "haiku" +target_os = "redox", +target_os = "fuchsia", +target_os = "haiku" )))] fn test_ttyname_invalid_fd() { assert_eq!(ttyname(-1), Err(Errno::EBADF)); @@ -1272,12 +1272,12 @@ fn test_ttyname_invalid_fd() { #[test] #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "openbsd", - target_os = "netbsd", - target_os = "dragonfly", +target_os = "macos", +target_os = "ios", +target_os = "freebsd", +target_os = "openbsd", +target_os = "netbsd", +target_os = "dragonfly", ))] fn test_getpeereid() { use std::os::unix::net::UnixStream; @@ -1297,12 +1297,12 @@ fn test_getpeereid() { #[test] #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "openbsd", - target_os = "netbsd", - target_os = "dragonfly", +target_os = "macos", +target_os = "ios", +target_os = "freebsd", +target_os = "openbsd", +target_os = "netbsd", +target_os = "dragonfly", ))] fn test_getpeereid_invalid_fd() { // getpeereid is not POSIX, so error codes are inconsistent between different Unices. @@ -1335,10 +1335,10 @@ fn test_faccessat_not_existing() { Some(dirfd), not_exist_file, AccessFlags::F_OK, - AtFlags::empty() + AtFlags::empty(), ) - .err() - .unwrap(), + .err() + .unwrap(), Errno::ENOENT ); } @@ -1354,9 +1354,9 @@ fn test_faccessat_none_file_exists() { None, &path, AccessFlags::R_OK | AccessFlags::W_OK, - AtFlags::empty() + AtFlags::empty(), ) - .is_ok()); + .is_ok()); } #[test] @@ -1372,7 +1372,7 @@ fn test_faccessat_file_exists() { Some(dirfd), &path, AccessFlags::R_OK | AccessFlags::W_OK, - AtFlags::empty() + AtFlags::empty(), ) - .is_ok()); + .is_ok()); } From 347915bdb590d9b3437b9c5c69c6f1652017d325 Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Tue, 9 Aug 2022 12:17:27 +0800 Subject: [PATCH 2/4] format code --- src/sys/time.rs | 50 +++++------ src/unistd.rs | 58 ++++++------ test/sys/test_ptrace.rs | 48 +++++----- test/test_stat.rs | 58 ++++++------ test/test_unistd.rs | 194 ++++++++++++++++++++-------------------- 5 files changed, 204 insertions(+), 204 deletions(-) diff --git a/src/sys/time.rs b/src/sys/time.rs index 3627997855..e7a72f0205 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -7,17 +7,17 @@ use std::time::Duration; use std::{cmp, fmt, ops}; #[cfg(any( -all(feature = "time", any(target_os = "android", target_os = "linux")), -all( -any( -target_os = "freebsd", -target_os = "illumos", -target_os = "linux", -target_os = "netbsd" -), -feature = "time", -feature = "signal" -) + all(feature = "time", any(target_os = "android", target_os = "linux")), + all( + any( + target_os = "freebsd", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd" + ), + feature = "time", + feature = "signal" + ) ))] pub(crate) mod timer { use crate::sys::time::TimeSpec; @@ -98,10 +98,10 @@ pub(crate) mod timer { } } #[cfg(any( - target_os = "freebsd", - target_os = "netbsd", - target_os = "dragonfly", - target_os = "illumos" + target_os = "freebsd", + target_os = "netbsd", + target_os = "dragonfly", + target_os = "illumos" ))] bitflags! { /// Flags that are used for arming the timer. @@ -114,17 +114,17 @@ pub(crate) mod timer { fn from(timerspec: TimerSpec) -> Expiration { match timerspec { TimerSpec(libc::itimerspec { - it_interval: - libc::timespec { - tv_sec: 0, - tv_nsec: 0, - }, - it_value: ts, - }) => Expiration::OneShot(ts.into()), + it_interval: + libc::timespec { + tv_sec: 0, + tv_nsec: 0, + }, + it_value: ts, + }) => Expiration::OneShot(ts.into()), TimerSpec(libc::itimerspec { - it_interval: int_ts, - it_value: val_ts, - }) => { + it_interval: int_ts, + it_value: val_ts, + }) => { if (int_ts.tv_sec == val_ts.tv_sec) && (int_ts.tv_nsec == val_ts.tv_nsec) { diff --git a/src/unistd.rs b/src/unistd.rs index 69419d640e..2209c06921 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -7,15 +7,15 @@ use crate::fcntl::{at_rawfd, AtFlags}; #[cfg(feature = "fs")] use crate::fcntl::{fcntl, FcntlArg::F_SETFD, FdFlag, OFlag}; #[cfg(all( -feature = "fs", -any( -target_os = "openbsd", -target_os = "netbsd", -target_os = "freebsd", -target_os = "dragonfly", -target_os = "macos", -target_os = "ios" -) + feature = "fs", + any( + target_os = "openbsd", + target_os = "netbsd", + target_os = "freebsd", + target_os = "dragonfly", + target_os = "macos", + target_os = "ios" + ) ))] use crate::sys::stat::FileFlag; #[cfg(feature = "fs")] @@ -45,20 +45,20 @@ feature! { } #[cfg(any( -target_os = "android", -target_os = "dragonfly", -target_os = "freebsd", -target_os = "linux", -target_os = "openbsd" + target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "linux", + target_os = "openbsd" ))] pub use self::setres::*; #[cfg(any( -target_os = "android", -target_os = "dragonfly", -target_os = "freebsd", -target_os = "linux", -target_os = "openbsd" + target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "linux", + target_os = "openbsd" ))] pub use self::getres::*; @@ -2752,11 +2752,11 @@ mod pivot_root { } #[cfg(any( -target_os = "android", -target_os = "dragonfly", -target_os = "freebsd", -target_os = "linux", -target_os = "openbsd" + target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "linux", + target_os = "openbsd" ))] mod setres { feature! { @@ -2801,11 +2801,11 @@ mod setres { } #[cfg(any( -target_os = "android", -target_os = "dragonfly", -target_os = "freebsd", -target_os = "linux", -target_os = "openbsd" + target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "linux", + target_os = "openbsd" ))] mod getres { feature! { diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index 1668058329..530560fe17 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -1,7 +1,7 @@ #[cfg(all( -target_os = "linux", -any(target_arch = "x86_64", target_arch = "x86"), -target_env = "gnu" + target_os = "linux", + any(target_arch = "x86_64", target_arch = "x86"), + target_env = "gnu" ))] use memoffset::offset_of; use nix::errno::Errno; @@ -111,17 +111,17 @@ fn test_ptrace_cont() { ptrace::cont(child, Some(Signal::SIGKILL)).unwrap(); match waitpid(child, None) { Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) - if pid == child => - { - // FIXME It's been observed on some systems (apple) the - // tracee may not be killed but remain as a zombie process - // affecting other wait based tests. Add an extra kill just - // to make sure there are no zombies. + if pid == child => + { + // FIXME It's been observed on some systems (apple) the + // tracee may not be killed but remain as a zombie process + // affecting other wait based tests. Add an extra kill just + // to make sure there are no zombies. + let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); - while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { - let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); - } } + } _ => panic!("The process should have been killed"), } } @@ -163,13 +163,13 @@ fn test_ptrace_interrupt() { ptrace::detach(child, Some(Signal::SIGKILL)).unwrap(); match waitpid(child, None) { Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) - if pid == child => - { + if pid == child => + { + let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); - while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { - let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); - } } + } _ => panic!("The process should have been killed"), } } @@ -178,9 +178,9 @@ fn test_ptrace_interrupt() { // ptrace::{setoptions, getregs} are only available in these platforms #[cfg(all( -target_os = "linux", -any(target_arch = "x86_64", target_arch = "x86"), -target_env = "gnu" + target_os = "linux", + any(target_arch = "x86_64", target_arch = "x86"), + target_env = "gnu" ))] #[test] fn test_ptrace_syscall() { @@ -219,18 +219,18 @@ fn test_ptrace_syscall() { .unwrap(); #[cfg(target_arch = "x86_64")] - let get_syscall_id = + let get_syscall_id = || ptrace::getregs(child).unwrap().orig_rax as libc::c_long; #[cfg(target_arch = "x86")] - let get_syscall_id = + let get_syscall_id = || ptrace::getregs(child).unwrap().orig_eax as libc::c_long; // this duplicates `get_syscall_id` for the purpose of testing `ptrace::read_user`. #[cfg(target_arch = "x86_64")] - let rax_offset = offset_of!(libc::user_regs_struct, orig_rax); + let rax_offset = offset_of!(libc::user_regs_struct, orig_rax); #[cfg(target_arch = "x86")] - let rax_offset = offset_of!(libc::user_regs_struct, orig_eax); + let rax_offset = offset_of!(libc::user_regs_struct, orig_eax); let get_syscall_from_user_area = || { // Find the offset of `user.regs.rax` (or `user.regs.eax` for x86) diff --git a/test/test_stat.rs b/test/test_stat.rs index bed33b5456..55f15c0771 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -20,11 +20,11 @@ use nix::errno::Errno; #[cfg(not(target_os = "redox"))] use nix::fcntl; #[cfg(any( -target_os = "linux", -target_os = "ios", -target_os = "macos", -target_os = "freebsd", -target_os = "netbsd" + target_os = "linux", + target_os = "ios", + target_os = "macos", + target_os = "freebsd", + target_os = "netbsd" ))] use nix::sys::stat::lutimes; #[cfg(not(any(target_os = "redox", target_os = "haiku")))] @@ -234,11 +234,11 @@ fn test_utimes() { #[test] #[cfg(any( -target_os = "linux", -target_os = "ios", -target_os = "macos", -target_os = "freebsd", -target_os = "netbsd" + target_os = "linux", + target_os = "ios", + target_os = "macos", + target_os = "freebsd", + target_os = "netbsd" ))] fn test_lutimes() { let tempdir = tempfile::tempdir().unwrap(); @@ -299,7 +299,7 @@ fn test_utimensat() { &TimeSpec::seconds(678), UtimensatFlags::FollowSymlink, ) - .unwrap(); + .unwrap(); assert_times_eq(12345, 678, &fs::metadata(&fullpath).unwrap()); chdir(tempdir.path()).unwrap(); @@ -311,7 +311,7 @@ fn test_utimensat() { &TimeSpec::seconds(800), UtimensatFlags::FollowSymlink, ) - .unwrap(); + .unwrap(); assert_times_eq(500, 800, &fs::metadata(&fullpath).unwrap()); } @@ -356,19 +356,19 @@ fn test_mkdirat_fail() { fcntl::OFlag::O_CREAT, stat::Mode::empty(), ) - .unwrap(); + .unwrap(); let result = mkdirat(dirfd, filename, Mode::S_IRWXU).unwrap_err(); assert_eq!(result, Errno::ENOTDIR); } #[test] #[cfg(not(any( -target_os = "dragonfly", -target_os = "freebsd", -target_os = "ios", -target_os = "macos", -target_os = "haiku", -target_os = "redox" + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "haiku", + target_os = "redox" )))] fn test_mknod() { use stat::{lstat, mknod, SFlag}; @@ -384,13 +384,13 @@ fn test_mknod() { #[test] #[cfg(not(any( -target_os = "dragonfly", -target_os = "freebsd", -target_os = "illumos", -target_os = "ios", -target_os = "macos", -target_os = "haiku", -target_os = "redox" + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "haiku", + target_os = "redox" )))] fn test_mknodat() { use fcntl::{AtFlags, OFlag}; @@ -408,14 +408,14 @@ fn test_mknodat() { Mode::S_IRWXU, 0, ) - .unwrap(); + .unwrap(); let mode = fstatat( target_dir.as_raw_fd(), file_name, AtFlags::AT_SYMLINK_NOFOLLOW, ) - .unwrap() - .st_mode as mode_t; + .unwrap() + .st_mode as mode_t; assert_eq!(mode & libc::S_IFREG, libc::S_IFREG); assert_eq!(mode & libc::S_IRWXU, libc::S_IRWXU); } diff --git a/test/test_unistd.rs b/test/test_unistd.rs index e4750d4b16..eee10103ad 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -6,9 +6,9 @@ use nix::fcntl::OFlag; #[cfg(not(target_os = "redox"))] use nix::fcntl::{self, open}; #[cfg(not(any( -target_os = "redox", -target_os = "fuchsia", -target_os = "haiku" + target_os = "redox", + target_os = "fuchsia", + target_os = "haiku" )))] use nix::pty::{grantpt, posix_openpt, ptsname, unlockpt}; #[cfg(not(target_os = "redox"))] @@ -28,9 +28,9 @@ use std::fs::{self, File}; use std::io::Write; use std::os::unix::prelude::*; #[cfg(not(any( -target_os = "fuchsia", -target_os = "redox", -target_os = "haiku" + target_os = "fuchsia", + target_os = "redox", + target_os = "haiku" )))] use std::path::Path; use tempfile::{tempdir, tempfile}; @@ -126,11 +126,11 @@ fn test_mkfifo_directory() { #[test] #[cfg(not(any( -target_os = "macos", -target_os = "ios", -target_os = "android", -target_os = "redox", -target_os = "haiku" + target_os = "macos", + target_os = "ios", + target_os = "android", + target_os = "redox", + target_os = "haiku" )))] fn test_mkfifoat_none() { let _m = crate::CWD_LOCK.read(); @@ -147,11 +147,11 @@ fn test_mkfifoat_none() { #[test] #[cfg(not(any( -target_os = "macos", -target_os = "ios", -target_os = "android", -target_os = "redox", -target_os = "haiku" + target_os = "macos", + target_os = "ios", + target_os = "android", + target_os = "redox", + target_os = "haiku" )))] fn test_mkfifoat() { use nix::fcntl; @@ -170,11 +170,11 @@ fn test_mkfifoat() { #[test] #[cfg(not(any( -target_os = "macos", -target_os = "ios", -target_os = "android", -target_os = "redox", -target_os = "haiku" + target_os = "macos", + target_os = "ios", + target_os = "android", + target_os = "redox", + target_os = "haiku" )))] fn test_mkfifoat_directory_none() { let _m = crate::CWD_LOCK.read(); @@ -186,11 +186,11 @@ fn test_mkfifoat_directory_none() { #[test] #[cfg(not(any( -target_os = "macos", -target_os = "ios", -target_os = "android", -target_os = "redox", -target_os = "haiku" + target_os = "macos", + target_os = "ios", + target_os = "android", + target_os = "redox", + target_os = "haiku" )))] fn test_mkfifoat_directory() { // mkfifoat should fail if a directory is given @@ -234,11 +234,11 @@ mod linux_android { #[test] // `getgroups()` and `setgroups()` do not behave as expected on Apple platforms #[cfg(not(any( -target_os = "ios", -target_os = "macos", -target_os = "redox", -target_os = "fuchsia", -target_os = "haiku" + target_os = "ios", + target_os = "macos", + target_os = "redox", + target_os = "fuchsia", + target_os = "haiku" )))] fn test_setgroups() { // Skip this test when not run as root as `setgroups()` requires root. @@ -263,12 +263,12 @@ fn test_setgroups() { #[test] // `getgroups()` and `setgroups()` do not behave as expected on Apple platforms #[cfg(not(any( -target_os = "ios", -target_os = "macos", -target_os = "redox", -target_os = "fuchsia", -target_os = "haiku", -target_os = "illumos" + target_os = "ios", + target_os = "macos", + target_os = "redox", + target_os = "fuchsia", + target_os = "haiku", + target_os = "illumos" )))] fn test_initgroups() { // Skip this test when not run as root as `initgroups()` and `setgroups()` @@ -609,9 +609,9 @@ cfg_if! { #[test] #[cfg(not(any( -target_os = "redox", -target_os = "fuchsia", -target_os = "haiku" + target_os = "redox", + target_os = "fuchsia", + target_os = "haiku" )))] fn test_acct() { use std::process::Command; @@ -685,11 +685,11 @@ fn test_sysconf_unsupported() { } #[cfg(any( -target_os = "android", -target_os = "dragonfly", -target_os = "freebsd", -target_os = "linux", -target_os = "openbsd" + target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "linux", + target_os = "openbsd" ))] #[test] fn test_getresuid() { @@ -700,11 +700,11 @@ fn test_getresuid() { } #[cfg(any( -target_os = "android", -target_os = "dragonfly", -target_os = "freebsd", -target_os = "linux", -target_os = "openbsd" + target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "linux", + target_os = "openbsd" ))] #[test] fn test_getresgid() { @@ -733,16 +733,16 @@ fn test_pipe() { // pipe2(2) is the same as pipe(2), except it allows setting some flags. Check // that we can set a flag. #[cfg(any( -target_os = "android", -target_os = "dragonfly", -target_os = "emscripten", -target_os = "freebsd", -target_os = "illumos", -target_os = "linux", -target_os = "netbsd", -target_os = "openbsd", -target_os = "redox", -target_os = "solaris" + target_os = "android", + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", + target_os = "solaris" ))] #[test] fn test_pipe2() { @@ -918,7 +918,7 @@ fn test_linkat_file() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); assert!(newfilepath.exists()); } @@ -944,7 +944,7 @@ fn test_linkat_olddirfd_none() { fcntl::OFlag::empty(), stat::Mode::empty(), ) - .unwrap(); + .unwrap(); // Attempt hard link file using curent working directory as relative path for old file path chdir(tempdir_oldfile.path()).unwrap(); @@ -955,7 +955,7 @@ fn test_linkat_olddirfd_none() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); assert!(newfilepath.exists()); } @@ -981,7 +981,7 @@ fn test_linkat_newdirfd_none() { fcntl::OFlag::empty(), stat::Mode::empty(), ) - .unwrap(); + .unwrap(); // Attempt hard link file using current working directory as relative path for new file path chdir(tempdir_newfile.path()).unwrap(); @@ -992,16 +992,16 @@ fn test_linkat_newdirfd_none() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); assert!(newfilepath.exists()); } #[test] #[cfg(not(any( -target_os = "ios", -target_os = "macos", -target_os = "redox", -target_os = "haiku" + target_os = "ios", + target_os = "macos", + target_os = "redox", + target_os = "haiku" )))] fn test_linkat_no_follow_symlink() { let _m = crate::CWD_LOCK.read(); @@ -1035,7 +1035,7 @@ fn test_linkat_no_follow_symlink() { newfilename, LinkatFlags::NoSymlinkFollow, ) - .unwrap(); + .unwrap(); // Assert newfile is actually a symlink to oldfile. assert_eq!( @@ -1078,7 +1078,7 @@ fn test_linkat_follow_symlink() { newfilename, LinkatFlags::SymlinkFollow, ) - .unwrap(); + .unwrap(); let newfilestat = stat::stat(&newfilepath).unwrap(); @@ -1180,10 +1180,10 @@ fn test_access_file_exists() { fn test_user_into_passwd() { // get the UID of the "nobody" user #[cfg(not(target_os = "haiku"))] - let test_username = "nobody"; + let test_username = "nobody"; // "nobody" unavailable on haiku #[cfg(target_os = "haiku")] - let test_username = "user"; + let test_username = "user"; let nobody = User::from_name(test_username).unwrap().unwrap(); let pwd: libc::passwd = nobody.into(); @@ -1221,8 +1221,8 @@ fn test_setfsuid() { let prev_fuid = setfsuid(Uid::from_raw(-1i32 as u32)); assert_ne!(prev_fuid, fuid); }) - .join() - .unwrap(); + .join() + .unwrap(); // open the temporary file with the current thread filesystem UID fs::File::open(temp_path_2).unwrap(); @@ -1230,9 +1230,9 @@ fn test_setfsuid() { #[test] #[cfg(not(any( -target_os = "redox", -target_os = "fuchsia", -target_os = "haiku" + target_os = "redox", + target_os = "fuchsia", + target_os = "haiku" )))] fn test_ttyname() { let fd = posix_openpt(OFlag::O_RDWR).expect("posix_openpt failed"); @@ -1262,9 +1262,9 @@ fn test_ttyname_not_pty() { #[test] #[cfg(not(any( -target_os = "redox", -target_os = "fuchsia", -target_os = "haiku" + target_os = "redox", + target_os = "fuchsia", + target_os = "haiku" )))] fn test_ttyname_invalid_fd() { assert_eq!(ttyname(-1), Err(Errno::EBADF)); @@ -1272,12 +1272,12 @@ fn test_ttyname_invalid_fd() { #[test] #[cfg(any( -target_os = "macos", -target_os = "ios", -target_os = "freebsd", -target_os = "openbsd", -target_os = "netbsd", -target_os = "dragonfly", + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly", ))] fn test_getpeereid() { use std::os::unix::net::UnixStream; @@ -1297,12 +1297,12 @@ fn test_getpeereid() { #[test] #[cfg(any( -target_os = "macos", -target_os = "ios", -target_os = "freebsd", -target_os = "openbsd", -target_os = "netbsd", -target_os = "dragonfly", + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly", ))] fn test_getpeereid_invalid_fd() { // getpeereid is not POSIX, so error codes are inconsistent between different Unices. @@ -1337,8 +1337,8 @@ fn test_faccessat_not_existing() { AccessFlags::F_OK, AtFlags::empty(), ) - .err() - .unwrap(), + .err() + .unwrap(), Errno::ENOENT ); } @@ -1356,7 +1356,7 @@ fn test_faccessat_none_file_exists() { AccessFlags::R_OK | AccessFlags::W_OK, AtFlags::empty(), ) - .is_ok()); + .is_ok()); } #[test] @@ -1374,5 +1374,5 @@ fn test_faccessat_file_exists() { AccessFlags::R_OK | AccessFlags::W_OK, AtFlags::empty(), ) - .is_ok()); + .is_ok()); } From 4d5e5d83f824f0ff2368636753e68ec189cf3a52 Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Tue, 9 Aug 2022 12:22:41 +0800 Subject: [PATCH 3/4] remove deprecated items --- src/sys/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/time.rs b/src/sys/time.rs index e7a72f0205..0cac7e8a29 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -196,7 +196,7 @@ const SECS_PER_HOUR: i64 = 3600; const TS_MAX_SECONDS: i64 = (i64::MAX / NANOS_PER_SEC) - 1; #[cfg(target_pointer_width = "32")] -const TS_MAX_SECONDS: i64 = ::std::isize::MAX as i64; +const TS_MAX_SECONDS: i64 = isize::MAX as i64; const TS_MIN_SECONDS: i64 = -TS_MAX_SECONDS; @@ -456,7 +456,7 @@ const MICROS_PER_SEC: i64 = 1_000_000; const TV_MAX_SECONDS: i64 = (i64::MAX / MICROS_PER_SEC) - 1; #[cfg(target_pointer_width = "32")] -const TV_MAX_SECONDS: i64 = ::std::isize::MAX as i64; +const TV_MAX_SECONDS: i64 = isize::MAX as i64; const TV_MIN_SECONDS: i64 = -TV_MAX_SECONDS; From 217c3b514148ff2c7bcfdfa808df2316d56db281 Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Fri, 12 Aug 2022 09:13:57 +0800 Subject: [PATCH 4/4] fix CI error --- src/sys/personality.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/personality.rs b/src/sys/personality.rs index 15b59017be..9e285ae6e0 100644 --- a/src/sys/personality.rs +++ b/src/sys/personality.rs @@ -86,7 +86,7 @@ pub fn get() -> Result { /// # use nix::sys::personality::{self, Persona}; /// let mut pers = personality::get().unwrap(); /// assert!(!pers.contains(Persona::ADDR_NO_RANDOMIZE)); -/// personality::set(pers | Persona::ADDR_NO_RANDOMIZE).unwrap().unwrap(); +/// personality::set(pers | Persona::ADDR_NO_RANDOMIZE).unwrap(); /// ``` pub fn set(persona: Persona) -> Result { let res = unsafe {