diff --git a/build.rs b/build.rs index 50943db2..96342d3b 100644 --- a/build.rs +++ b/build.rs @@ -24,5 +24,6 @@ fn main() { freebsdlike: { any(dragonfly, freebsd) }, netbsdlike: { any(netbsd, openbsd) }, solarish: { any(illumos, solaris) }, + bsd_not_nto: {all(bsd,not(target_os = "nto"))}, } } diff --git a/src/fcntl.rs b/src/fcntl.rs index 4b99abd3..c8f1294d 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -123,12 +123,12 @@ libc_bitflags!( #[cfg(target_os = "freebsd")] O_EXEC; /// Open with an exclusive file lock. - #[cfg(any(bsd, target_os = "redox"))] + #[cfg(all(any(bsd, target_os = "redox"), not(target_os = "nto")))] O_EXLOCK; /// Same as `O_SYNC`. - #[cfg(any(bsd, + #[cfg(all(any(bsd, all(target_os = "linux", not(target_env = "musl"), not(target_env = "ohos")), - target_os = "redox"))] + target_os = "redox"), not(target_os = "nto")))] O_FSYNC; /// Allow files whose sizes can't be represented in an `off_t` to be opened. #[cfg(linux_android)] @@ -169,7 +169,7 @@ libc_bitflags!( #[cfg(target_os = "netbsd")] O_SEARCH; /// Open with a shared file lock. - #[cfg(any(bsd, target_os = "redox"))] + #[cfg(all(any(bsd, target_os = "redox"),not(target_os="nto")))] O_SHLOCK; /// Implicitly follow each `write()` with an `fsync()`. #[cfg(not(target_os = "redox"))] @@ -468,7 +468,7 @@ fn readlink_maybe_at( cstr.as_ptr(), v.as_mut_ptr().cast(), v.capacity() as size_t, - ), + ) as libc::ssize_t, } }) } diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs index 248e0ab1..f3695f34 100644 --- a/src/mount/bsd.rs +++ b/src/mount/bsd.rs @@ -2,8 +2,10 @@ use crate::Error; use crate::{Errno, NixPath, Result}; use libc::c_int; -#[cfg(target_os = "freebsd")] +#[cfg(any(target_os = "freebsd"))] use libc::{c_char, c_uint, c_void}; +#[cfg(target_os = "nto")] +use libc::c_char; #[cfg(target_os = "freebsd")] use std::{ borrow::Cow, @@ -19,12 +21,14 @@ libc_bitflags!( #[cfg(any(target_os = "netbsd", target_os = "freebsd"))] MNT_ACLS; /// All I/O to the file system should be done asynchronously. + #[cfg(bsd_not_nto)] MNT_ASYNC; /// dir should instead be a file system ID encoded as “FSID:val0:val1”. #[cfg(target_os = "freebsd")] MNT_BYFSID; /// Force a read-write mount even if the file system appears to be /// unclean. + #[cfg(bsd_not_nto)] MNT_FORCE; /// GEOM journal support enabled. #[cfg(target_os = "freebsd")] @@ -42,6 +46,7 @@ libc_bitflags!( #[cfg(target_os = "freebsd")] MNT_NFS4ACLS; /// Do not update access times. + #[cfg(bsd_not_nto)] MNT_NOATIME; /// Disallow program execution. MNT_NOEXEC; @@ -54,6 +59,7 @@ libc_bitflags!( MNT_RDONLY; /// Causes the vfs subsystem to update its data structures pertaining to /// the specified already mounted file system. + #[cfg(bsd_not_nto)] MNT_RELOAD; /// Create a snapshot of the file system. /// @@ -68,6 +74,7 @@ libc_bitflags!( #[cfg(freebsdlike)] MNT_SUIDDIR; /// All I/O to the file system should be done synchronously. + #[cfg(bsd_not_nto)] MNT_SYNCHRONOUS; /// Union with underlying fs. #[cfg(any( @@ -78,6 +85,7 @@ libc_bitflags!( MNT_UNION; /// Indicates that the mount command is being applied to an already /// mounted file system. + #[cfg(bsd_not_nto)] MNT_UPDATE; /// Check vnode use counts. #[cfg(target_os = "freebsd")] @@ -402,6 +410,15 @@ impl<'a> Drop for Nmount<'a> { } } +#[cfg(target_os = "nto")] +fn unmount_impl(mountpoint: *const c_char, flags: MntFlags) -> c_int { + unsafe { libc::umount(mountpoint, flags.bits()) } +} + +#[cfg(bsd_not_nto)] +fn unmount_impl(mountpoint: *const c_char, flags: MntFlags) -> c_int { + unsafe { libc::unmount(mountpoint, flags.bits()) } +} /// Unmount the file system mounted at `mountpoint`. /// /// Useful flags include @@ -422,8 +439,8 @@ pub fn unmount

(mountpoint: &P, flags: MntFlags) -> Result<()> where P: ?Sized + NixPath, { - let res = mountpoint.with_nix_path(|cstr| unsafe { - libc::unmount(cstr.as_ptr(), flags.bits()) + let res = mountpoint.with_nix_path(|cstr| { + unmount_impl(cstr.as_ptr(), flags) })?; Errno::result(res).map(drop) diff --git a/src/sys/ioctl/bsd.rs b/src/sys/ioctl/bsd.rs index cedc8e63..ad78a808 100644 --- a/src/sys/ioctl/bsd.rs +++ b/src/sys/ioctl/bsd.rs @@ -1,10 +1,10 @@ /// The datatype used for the ioctl number #[doc(hidden)] -#[cfg(not(solarish))] +#[cfg(all(not(solarish), not(target_os = "nto")))] pub type ioctl_num_type = ::libc::c_ulong; #[doc(hidden)] -#[cfg(solarish)] +#[cfg(any(solarish, target_os = "nto"))] pub type ioctl_num_type = ::libc::c_int; /// The datatype used for the 3rd argument diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 93339d19..49d34c8c 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -17,7 +17,7 @@ feature! { #[allow(missing_docs)] pub mod epoll; - #[cfg(bsd)] + #[cfg(bsd_not_nto)] pub mod event; #[cfg(any(linux_android, target_os = "freebsd"))] @@ -66,7 +66,7 @@ feature! { pub mod pthread; } -#[cfg(any(linux_android, bsd))] +#[cfg(any(linux_android, bsd_not_nto))] feature! { #![feature = "ptrace"] #[allow(missing_docs)] diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 5c951c82..60081ac6 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -2165,6 +2165,13 @@ mod tests { fn test_ipv4addr_to_libc() { let s = std::net::Ipv4Addr::new(1, 2, 3, 4); let l = ipv4addr_to_libc(s); + #[cfg(target_os = "nto")] + { + let ptr = std::ptr::addr_of!(l.s_addr); + let val = unsafe { ptr.read_unaligned() }; + assert_eq!(val, u32::to_be(0x01020304)); + } + #[cfg(not(target_os = "nto"))] assert_eq!(l.s_addr, u32::to_be(0x01020304)); } diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index c321d3fd..a116b60f 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -927,7 +927,7 @@ impl ControlMessageOwned { } #[cfg(target_os = "nto")] (libc::SOL_SOCKET, libc::SCM_CREDS) => { - let cred: libc::sockcred = ptr::read_unaligned(p as *const _); + let cred: libc::sockcred = unsafe { ptr::read_unaligned(p as *const _) }; ControlMessageOwned::ScmCreds(cred.into()) } #[cfg(not(any(target_os = "aix", target_os = "haiku")))] @@ -1275,7 +1275,7 @@ impl<'a> ControlMessage<'a> { #[cfg(feature = "net")] ControlMessage::Ipv4PacketInfo(info) => info as *const _ as *const u8, #[cfg(any(linux_android, target_os = "netbsd", - target_os = "freebsd", apple_targets))] + target_os = "freebsd", apple_targets, target_os = "nto",))] #[cfg(feature = "net")] ControlMessage::Ipv6PacketInfo(info) => info as *const _ as *const u8, #[cfg(any(freebsdlike, netbsdlike))] diff --git a/src/sys/stat.rs b/src/sys/stat.rs index c5854eec..3de2a2a4 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -1,4 +1,4 @@ -#[cfg(any(apple_targets, target_os = "openbsd"))] +#[cfg(any(apple_targets, target_os = "openbsd", target_os = "nto"))] pub use libc::c_uint; #[cfg(any(target_os = "netbsd", freebsdlike))] pub use libc::c_ulong; @@ -61,7 +61,7 @@ libc_bitflags! { } } -#[cfg(any(apple_targets, target_os = "openbsd"))] +#[cfg(any(apple_targets, target_os = "openbsd", target_os = "nto"))] pub type type_of_file_flag = c_uint; #[cfg(any(freebsdlike, target_os = "netbsd"))] pub type type_of_file_flag = c_ulong; @@ -71,12 +71,15 @@ libc_bitflags! { /// File flags. pub struct FileFlag: type_of_file_flag { /// The file may only be appended to. + #[cfg(not(target_os = "nto"))] SF_APPEND; /// The file has been archived. + #[cfg(not(target_os = "nto"))] SF_ARCHIVED; #[cfg(any(target_os = "dragonfly"))] SF_CACHE; /// The file may not be changed. + #[cfg(not(target_os = "nto"))] SF_IMMUTABLE; /// Indicates a WAPBL journal file. #[cfg(any(target_os = "netbsd"))] @@ -88,6 +91,7 @@ libc_bitflags! { #[cfg(freebsdlike)] SF_NOUNLINK; /// Mask of superuser changeable flags + #[cfg(not(target_os = "nto"))] SF_SETTABLE; /// Snapshot is invalid. #[cfg(any(target_os = "netbsd"))] @@ -98,6 +102,7 @@ libc_bitflags! { #[cfg(any(target_os = "dragonfly"))] SF_XLINK; /// The file may only be appended to. + #[cfg(not(target_os = "nto"))] UF_APPEND; /// The file needs to be archived. #[cfg(any(target_os = "freebsd"))] @@ -115,8 +120,10 @@ libc_bitflags! { ))] UF_HIDDEN; /// The file may not be changed. + #[cfg(not(target_os = "nto"))] UF_IMMUTABLE; /// Do not dump the file. + #[cfg(not(target_os = "nto"))] UF_NODUMP; #[cfg(any(target_os = "dragonfly"))] UF_NOHISTORY; @@ -128,6 +135,7 @@ libc_bitflags! { #[cfg(any(target_os = "freebsd"))] UF_OFFLINE; /// The directory is opaque when viewed through a union stack. + #[cfg(not(target_os = "nto"))] UF_OPAQUE; /// The file is read only, and may not be written or appended. #[cfg(any(target_os = "freebsd"))] @@ -136,6 +144,7 @@ libc_bitflags! { #[cfg(any(target_os = "freebsd"))] UF_REPARSE; /// Mask of owner changeable flags. + #[cfg(not(target_os = "nto"))] UF_SETTABLE; /// The file has the Windows `FILE_ATTRIBUTE_SPARSE_FILE` attribute. #[cfg(any(target_os = "freebsd"))] diff --git a/src/sys/termios.rs b/src/sys/termios.rs index d9ee4045..7b845480 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -282,13 +282,13 @@ libc_enum! { B1800, B2400, B4800, - #[cfg(bsd)] + #[cfg(bsd_not_nto)] B7200, B9600, - #[cfg(bsd)] + #[cfg(bsd_not_nto)] B14400, B19200, - #[cfg(bsd)] + #[cfg(bsd_not_nto)] B28800, B38400, #[cfg(not(target_os = "aix"))] @@ -431,7 +431,7 @@ libc_enum! { #[cfg(not(target_os = "haiku"))] VREPRINT, VSTART, - #[cfg(any(bsd, solarish))] + #[cfg(any(bsd_not_nto, solarish))] VSTATUS, VSTOP, VSUSP, @@ -589,9 +589,9 @@ libc_bitflags! { target_os = "nto", apple_targets))] FF1 as tcflag_t; - #[cfg(bsd)] + #[cfg(bsd_not_nto)] OXTABS; - #[cfg(bsd)] + #[cfg(bsd_not_nto)] ONOEOT as tcflag_t; // Bitmasks for use with OutputFlags to select specific settings @@ -635,7 +635,7 @@ libc_bitflags! { libc_bitflags! { /// Flags for setting the control mode of a terminal pub struct ControlFlags: tcflag_t { - #[cfg(bsd)] + #[cfg(bsd_not_nto)] CIGNORE; CS5; CS6; @@ -659,7 +659,7 @@ libc_bitflags! { CIBAUD; #[cfg(linux_android)] CBAUDEX; - #[cfg(bsd)] + #[cfg(bsd_not_nto)] MDMBUF; #[cfg(netbsdlike)] CHWFLOW; @@ -697,7 +697,7 @@ libc_bitflags! { ECHOCTL; ISIG; ICANON; - #[cfg(bsd)] + #[cfg(bsd_not_nto)] ALTWERASE; IEXTEN; #[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "aix", target_os = "nto",)))] @@ -705,7 +705,7 @@ libc_bitflags! { TOSTOP; #[cfg(not(any(target_os = "redox", target_os = "nto")))] FLUSHO; - #[cfg(bsd)] + #[cfg(bsd_not_nto)] NOKERNINFO; #[cfg(not(any(target_os = "redox", target_os = "nto")))] PENDIN; diff --git a/src/unistd.rs b/src/unistd.rs index ecf2e2ed..e58b42ac 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -23,7 +23,7 @@ use crate::fcntl::AtFlags; target_os = "redox", ))] use crate::fcntl::OFlag; -#[cfg(all(feature = "fs", bsd))] +#[cfg(all(feature = "fs", bsd_not_nto))] use crate::sys::stat::FileFlag; #[cfg(feature = "fs")] use crate::sys::stat::Mode; @@ -3362,6 +3362,7 @@ impl From for libc::passwd { target_os = "fuchsia", target_os = "haiku", target_os = "hurd", + target_os = "nto", )))] pw_expire: u.expire, #[cfg(any(solarish, target_os = "nto",))] @@ -3687,7 +3688,7 @@ feature! { /// Set the file flags. /// /// See also [chflags(2)](https://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=2) -#[cfg(bsd)] +#[cfg(bsd_not_nto)] pub fn chflags(path: &P, flags: FileFlag) -> Result<()> { let res = path.with_nix_path(|cstr| unsafe { libc::chflags(cstr.as_ptr(), flags.bits()) diff --git a/test/sys/mod.rs b/test/sys/mod.rs index fb3f6be0..0c808b02 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -66,7 +66,7 @@ mod test_timerfd; ))] mod test_timer; -#[cfg(bsd)] +#[cfg(bsd_not_nto)] mod test_event; mod test_statvfs; mod test_time; diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs index 08843bf6..854f7991 100644 --- a/test/sys/test_ioctl.rs +++ b/test/sys/test_ioctl.rs @@ -163,6 +163,7 @@ mod bsd { assert_eq!(request_code_write_int!(b'p', 2), 0x2004_7002); } + #[cfg(not(target_os = "nto"))] #[test] fn test_op_write() { assert_eq!(request_code_write!(b'z', 10, 1), 0x8001_7A0A); @@ -170,6 +171,7 @@ mod bsd { } #[cfg(target_pointer_width = "64")] + #[cfg(not(target_os = "nto"))] #[test] fn test_op_write_64() { assert_eq!(request_code_write!(b'z', 10, 1u64 << 32), 0x8000_7A0A); @@ -187,12 +189,14 @@ mod bsd { assert_eq!(request_code_read!(b'z', 10, 1u64 << 32), 0x4000_7A0A); } + #[cfg(not(target_os = "nto"))] #[test] fn test_op_read_write() { assert_eq!(request_code_readwrite!(b'z', 10, 1), 0xC001_7A0A); assert_eq!(request_code_readwrite!(b'z', 10, 512), 0xC200_7A0A); } + #[cfg(not(target_os = "nto"))] #[cfg(target_pointer_width = "64")] #[test] fn test_op_read_write_64() { diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs index bf607497..cbe46f52 100644 --- a/test/sys/test_signal.rs +++ b/test/sys/test_signal.rs @@ -294,14 +294,18 @@ fn test_sigaction() { let handler_sig = SigHandler::Handler(test_sigaction_handler); + #[cfg(not(target_os = "nto"))] let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART | SaFlags::SA_SIGINFO; + #[cfg(target_os = "nto")] + let flags = SaFlags::SA_SIGINFO; let mut mask = SigSet::empty(); mask.add(SIGUSR1); let action_sig = SigAction::new(handler_sig, flags, mask); + #[cfg(not(target_os = "nto"))] assert_eq!( action_sig.flags(), SaFlags::SA_ONSTACK | SaFlags::SA_RESTART diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index ee60e62b..e3121a63 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1948,11 +1948,34 @@ pub fn test_recvif() { ControlMessageOwned::Ipv4RecvDstAddr(addr) => { rx_recvdstaddr = true; if let Some(sin) = lo.as_sockaddr_in() { - assert_eq!(sin.as_ref().sin_addr.s_addr, - addr.s_addr, - "unexpected destination address (expected {}, got {})", - sin.as_ref().sin_addr.s_addr, - addr.s_addr); + #[cfg(target_os = "nto")] + { + let sin_addr_ptr = std::ptr::addr_of!( + sin.as_ref().sin_addr.s_addr + ); + let sin_addr = unsafe { + std::ptr::read_unaligned(sin_addr_ptr) + }; + + let addr_addr_ptr = std::ptr::addr_of!(addr.s_addr); + let addr_addr = unsafe { + std::ptr::read_unaligned(addr_addr_ptr) + }; + + assert_eq!(sin_addr, + addr_addr, + "unexpected destination address (expected {}, got {})", + sin_addr, + addr_addr); + } + #[cfg(not(target_os = "nto"))] + { + assert_eq!(sin.as_ref().sin_addr.s_addr, + addr.s_addr, + "unexpected destination address (expected {}, got {})", + sin.as_ref().sin_addr.s_addr, + addr.s_addr); + } } else { panic!("unexpected Sockaddr"); } diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index d035a7bb..20727d0f 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -143,7 +143,8 @@ fn test_pread() { #[cfg(not(any( target_os = "redox", target_os = "haiku", - target_os = "solaris" + target_os = "solaris", + target_os = "nto", )))] fn test_pwritev() { use std::io::Read; @@ -182,7 +183,8 @@ fn test_pwritev() { #[cfg(not(any( target_os = "redox", target_os = "haiku", - target_os = "solaris" + target_os = "solaris", + target_os = "nto", )))] fn test_preadv() { use std::io::Write; diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index e4ace020..3e6e4711 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -42,9 +42,12 @@ fn test_openat() { let mut tmp = NamedTempFile::new().unwrap(); tmp.write_all(CONTENTS).unwrap(); - let dirfd = - open(tmp.path().parent().unwrap(), OFlag::empty(), Mode::empty()) - .unwrap(); + let dirfd = open( + tmp.path().parent().unwrap(), + OFlag::O_DIRECTORY, + Mode::empty(), + ) + .unwrap(); let fd = openat( Some(dirfd), tmp.path().file_name().unwrap(), @@ -124,12 +127,12 @@ fn test_openat2_forbidden() { fn test_renameat() { let old_dir = tempfile::tempdir().unwrap(); let old_dirfd = - open(old_dir.path(), OFlag::empty(), Mode::empty()).unwrap(); + open(old_dir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); let old_path = old_dir.path().join("old"); File::create(old_path).unwrap(); let new_dir = tempfile::tempdir().unwrap(); let new_dirfd = - open(new_dir.path(), OFlag::empty(), Mode::empty()).unwrap(); + open(new_dir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); renameat(Some(old_dirfd), "old", Some(new_dirfd), "new").unwrap(); assert_eq!( renameat(Some(old_dirfd), "old", Some(new_dirfd), "new").unwrap_err(), @@ -279,7 +282,8 @@ fn test_readlink() { let dst = tempdir.path().join("b"); println!("a: {:?}, b: {:?}", &src, &dst); fs::symlink(src.as_path(), dst.as_path()).unwrap(); - let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let dirfd = + open(tempdir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); let expected_dir = src.to_str().unwrap(); assert_eq!(readlink(&dst).unwrap().to_str().unwrap(), expected_dir); diff --git a/test/test_poll.rs b/test/test_poll.rs index fcb32549..02d02464 100644 --- a/test/test_poll.rs +++ b/test/test_poll.rs @@ -20,7 +20,11 @@ macro_rules! loop_while_eintr { #[test] fn test_poll() { let (r, w) = pipe().unwrap(); + + #[cfg(not(target_os = "nto"))] let mut fds = [PollFd::new(r.as_fd(), PollFlags::POLLIN)]; + #[cfg(target_os = "nto")] + let mut fds = [PollFd::new(r.as_fd(), PollFlags::POLLRDNORM)]; // Poll an idle pipe. Should timeout let nfds = loop_while_eintr!(poll(&mut fds, PollTimeout::from(100u8))); @@ -32,7 +36,10 @@ fn test_poll() { // Poll a readable pipe. Should return an event. let nfds = poll(&mut fds, PollTimeout::from(100u8)).unwrap(); assert_eq!(nfds, 1); + #[cfg(not(target_os = "nto"))] assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN)); + #[cfg(target_os = "nto")] + assert!(fds[0].revents().unwrap().contains(PollFlags::POLLRDNORM)); } // ppoll(2) is the same as poll except for how it handles timeouts and signals. diff --git a/test/test_pty.rs b/test/test_pty.rs index dda8b3f6..8b51ca51 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -1,4 +1,7 @@ use std::fs::File; +#[cfg(target_os = "nto")] +use std::io::stdout; +#[cfg(not(target_os = "nto"))] use std::io::{stdout, Read, Write}; use std::os::unix::prelude::*; use std::path::Path; @@ -7,6 +10,7 @@ use libc::_exit; use nix::fcntl::{open, OFlag}; use nix::pty::*; use nix::sys::stat; +#[cfg(not(target_os = "nto"))] use nix::sys::termios::*; use nix::sys::wait::WaitStatus; use nix::unistd::{pause, write}; @@ -136,6 +140,7 @@ fn test_open_ptty_pair() { } /// Put the terminal in raw mode. +#[cfg(not(target_os = "nto"))] fn make_raw(fd: Fd) { let mut termios = tcgetattr(&fd).unwrap(); cfmakeraw(&mut termios); @@ -144,6 +149,7 @@ fn make_raw(fd: Fd) { /// Test `io::Read` on the PTTY master #[test] +#[cfg(not(target_os = "nto"))] fn test_read_ptty_pair() { let (mut master, mut slave) = open_ptty_pair(); make_raw(&slave); @@ -161,6 +167,7 @@ fn test_read_ptty_pair() { /// Test `io::Write` on the PTTY master #[test] +#[cfg(not(target_os = "nto"))] fn test_write_ptty_pair() { let (mut master, mut slave) = open_ptty_pair(); make_raw(&slave); @@ -177,6 +184,7 @@ fn test_write_ptty_pair() { } #[test] +#[cfg(not(target_os = "nto"))] fn test_openpty() { // openpty uses ptname(3) internally let _m = crate::PTSNAME_MTX.lock(); @@ -207,6 +215,7 @@ fn test_openpty() { } #[test] +#[cfg(not(target_os = "nto"))] fn test_openpty_with_termios() { // openpty uses ptname(3) internally let _m = crate::PTSNAME_MTX.lock(); diff --git a/test/test_stat.rs b/test/test_stat.rs index 386f1084..99beeeb3 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -176,9 +176,12 @@ fn test_fchmodat() { let fullpath = tempdir.path().join(filename); File::create(&fullpath).unwrap(); - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); let mut mode1 = Mode::empty(); mode1.insert(Mode::S_IRUSR); @@ -286,9 +289,12 @@ fn test_utimensat() { let fullpath = tempdir.path().join(filename); drop(File::create(&fullpath).unwrap()); - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); utimensat( Some(dirfd), @@ -318,9 +324,12 @@ fn test_utimensat() { fn test_mkdirat_success_path() { let tempdir = tempfile::tempdir().unwrap(); let filename = "example_subdir"; - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); mkdirat(Some(dirfd), filename, Mode::S_IRWXU).expect("mkdirat failed"); assert!(Path::exists(&tempdir.path().join(filename))); } @@ -332,9 +341,12 @@ fn test_mkdirat_success_mode() { stat::SFlag::S_IFDIR.bits() | stat::Mode::S_IRWXU.bits(); let tempdir = tempfile::tempdir().unwrap(); let filename = "example_subdir"; - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); mkdirat(Some(dirfd), filename, Mode::S_IRWXU).expect("mkdirat failed"); let permissions = fs::metadata(tempdir.path().join(filename)) .unwrap() @@ -454,9 +466,12 @@ fn test_utimensat_unchanged() { let filename = "foo.txt"; let fullpath = tempdir.path().join(filename); drop(File::create(&fullpath).unwrap()); - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); let old_atime = fs::metadata(fullpath.as_path()) .unwrap() diff --git a/test/test_unistd.rs b/test/test_unistd.rs index aa2e5e56..4d8bf0ac 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -186,7 +186,8 @@ fn test_mkfifoat() { use nix::fcntl; let tempdir = tempdir().unwrap(); - let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let dirfd = + open(tempdir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); let mkfifoat_name = "mkfifoat_name"; mkfifoat(Some(dirfd), mkfifoat_name, Mode::S_IRUSR).unwrap(); @@ -223,7 +224,8 @@ fn test_mkfifoat_directory_none() { fn test_mkfifoat_directory() { // mkfifoat should fail if a directory is given let tempdir = tempdir().unwrap(); - let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let dirfd = + open(tempdir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); let mkfifoat_dir = "mkfifoat_dir"; stat::mkdirat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR).unwrap(); @@ -445,7 +447,8 @@ cfg_if! { target_os = "haiku", target_os = "hurd", target_os = "linux", - target_os = "openbsd" + target_os = "openbsd", + target_os = "nto", ))] execve_test_factory!(test_execvpe, execvpe, &CString::new("sh").unwrap()); @@ -564,7 +567,8 @@ fn test_fchownat() { File::create(&path).unwrap(); } - let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let dirfd = + open(tempdir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); fchownat(Some(dirfd), "file", uid, gid, AtFlags::empty()).unwrap(); @@ -617,7 +621,7 @@ cfg_if! { skip_if_jailed!("test_acct"); } } - } else if #[cfg(not(any(target_os = "redox", target_os = "fuchsia", target_os = "haiku")))] { + } else if #[cfg(not(any(target_os = "redox", target_os = "fuchsia", target_os = "haiku", target_os = "nto")))] { macro_rules! require_acct{ () => { skip_if_not_root!("test_acct"); @@ -630,7 +634,8 @@ cfg_if! { #[cfg(not(any( target_os = "redox", target_os = "fuchsia", - target_os = "haiku" + target_os = "haiku", + target_os = "nto", )))] fn test_acct() { use std::process::Command; @@ -674,7 +679,7 @@ fn test_fpathconf_limited() { #[test] fn test_pathconf_limited() { // PATH_MAX is limited on most platforms, so it makes a good test - let path_max = pathconf("/", PathconfVar::PATH_MAX); + let path_max = pathconf("/tmp", PathconfVar::PATH_MAX); assert!( path_max .expect("pathconf failed") @@ -822,8 +827,12 @@ fn test_alarm() { let _m = crate::SIGNAL_MTX.lock(); let handler = SigHandler::Handler(alarm_signal_handler); + #[cfg(not(target_os = "nto"))] let signal_action = SigAction::new(handler, SaFlags::SA_RESTART, SigSet::empty()); + #[cfg(target_os = "nto")] + let signal_action = + SigAction::new(handler, SaFlags::SA_SIGINFO, SigSet::empty()); let old_handler = unsafe { sigaction(Signal::SIGALRM, &signal_action) .expect("unable to set signal handler for alarm") @@ -881,7 +890,8 @@ fn test_symlinkat() { target.to_str().unwrap() ); - let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let dirfd = + open(tempdir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); let target = "c"; let linkpath = "d"; symlinkat(target, Some(dirfd), linkpath).unwrap(); @@ -910,9 +920,12 @@ fn test_linkat_file() { File::create(oldfilepath).unwrap(); // Get file descriptor for base directory - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); // Attempt hard link file at relative path linkat( @@ -947,7 +960,7 @@ fn test_linkat_olddirfd_none() { // Get file descriptor for base directory of new file let dirfd = fcntl::open( tempdir_newfile.path(), - fcntl::OFlag::empty(), + fcntl::OFlag::O_DIRECTORY, stat::Mode::empty(), ) .unwrap(); @@ -986,7 +999,7 @@ fn test_linkat_newdirfd_none() { // Get file descriptor for base directory of old file let dirfd = fcntl::open( tempdir_oldfile.path(), - fcntl::OFlag::empty(), + fcntl::OFlag::O_DIRECTORY, stat::Mode::empty(), ) .unwrap(); @@ -1028,9 +1041,12 @@ fn test_linkat_no_follow_symlink() { symlinkat(&oldfilepath, None, &symoldfilepath).unwrap(); // Get file descriptor for base directory - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); // Attempt link symlink of file at relative path linkat( @@ -1073,9 +1089,12 @@ fn test_linkat_follow_symlink() { symlinkat(&oldfilepath, None, &symoldfilepath).unwrap(); // Get file descriptor for base directory - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); // Attempt link target of symlink of file at relative path linkat( @@ -1111,9 +1130,12 @@ fn test_unlinkat_dir_noremovedir() { DirBuilder::new().recursive(true).create(dirpath).unwrap(); // Get file descriptor for base directory - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); // Attempt unlink dir at relative path without proper flag let err_result = @@ -1132,9 +1154,12 @@ fn test_unlinkat_dir_removedir() { DirBuilder::new().recursive(true).create(&dirpath).unwrap(); // Get file descriptor for base directory - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); // Attempt unlink dir at relative path with proper flag unlinkat(Some(dirfd), dirname, UnlinkatFlags::RemoveDir).unwrap(); @@ -1152,9 +1177,12 @@ fn test_unlinkat_file() { File::create(&filepath).unwrap(); // Get file descriptor for base directory - let dirfd = - fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()) - .unwrap(); + let dirfd = fcntl::open( + tempdir.path(), + fcntl::OFlag::O_DIRECTORY, + stat::Mode::empty(), + ) + .unwrap(); // Attempt unlink file at relative path unlinkat(Some(dirfd), filename, UnlinkatFlags::NoRemoveDir).unwrap(); @@ -1267,7 +1295,7 @@ fn test_ttyname_not_pty() { } #[test] -#[cfg(bsd)] +#[cfg(bsd_not_nto)] fn test_getpeereid() { use std::os::unix::net::UnixStream; let (sock_a, sock_b) = UnixStream::pair().unwrap(); @@ -1303,7 +1331,8 @@ fn test_faccessat_none_not_existing() { fn test_faccessat_not_existing() { use nix::fcntl::AtFlags; let tempdir = tempfile::tempdir().unwrap(); - let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let dirfd = + open(tempdir.path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); let not_exist_file = "does_not_exist.txt"; assert_eq!( faccessat(