From d310377786d4ea4137b0b35c0a1134ea5dd9cf64 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 3 Dec 2023 16:45:25 +0000 Subject: [PATCH] fix, mostly, solaris build. With few exceptions as newer interfaces like preadv/pwritev unsupported only on solaris. --- changelog/2248.fixed.md | 2 ++ src/lib.rs | 2 +- src/net/if_.rs | 24 ++---------------------- src/sys/ioctl/bsd.rs | 4 ++-- src/sys/ioctl/mod.rs | 4 ++-- src/sys/mod.rs | 6 +++--- src/sys/socket/addr.rs | 38 +++++++++++++++++++------------------- src/sys/socket/mod.rs | 9 ++++----- src/sys/time.rs | 4 ++-- src/sys/uio.rs | 4 ++-- src/unistd.rs | 6 +++--- test/sys/test_uio.rs | 12 ++++++++++-- test/test.rs | 2 +- test/test_dir.rs | 4 ++-- test/test_pty.rs | 2 +- test/test_resource.rs | 4 ++-- test/test_stat.rs | 2 +- test/test_unistd.rs | 6 +++--- 18 files changed, 62 insertions(+), 73 deletions(-) create mode 100644 changelog/2248.fixed.md diff --git a/changelog/2248.fixed.md b/changelog/2248.fixed.md new file mode 100644 index 0000000000..682e864b2b --- /dev/null +++ b/changelog/2248.fixed.md @@ -0,0 +1,2 @@ +Fixed solaris build globally. +Removed a subset of `InterfaceFlags` values specific to solaris/illumos as they are of i64 thus could not be cast to the expected i32 type. diff --git a/src/lib.rs b/src/lib.rs index 0d4416926f..aaf1c2d4c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,7 +125,7 @@ feature! { #[cfg(any(linux_android, bsd, - target_os = "illumos"))] + solarish))] #[deny(missing_docs)] pub mod ifaddrs; #[cfg(not(target_os = "redox"))] diff --git a/src/net/if_.rs b/src/net/if_.rs index 4e59fc15da..e74bf7aa14 100644 --- a/src/net/if_.rs +++ b/src/net/if_.rs @@ -213,26 +213,6 @@ libc_bitflags!( /// Interface is offline #[cfg(solarish)] IFF_OFFLINE; - #[cfg(target_os = "solaris")] - IFF_COS_ENABLED; - /// Prefer as source addr. - #[cfg(target_os = "solaris")] - IFF_PREFERRED; - /// RFC3041 - #[cfg(target_os = "solaris")] - IFF_TEMPORARY; - /// MTU set with SIOCSLIFMTU - #[cfg(target_os = "solaris")] - IFF_FIXEDMTU; - /// Cannot send / receive packets - #[cfg(target_os = "solaris")] - IFF_VIRTUAL; - /// Local address in use - #[cfg(target_os = "solaris")] - IFF_DUPLICATE; - /// IPMP IP interface - #[cfg(target_os = "solaris")] - IFF_IPMP; } ); @@ -247,7 +227,7 @@ impl fmt::Display for InterfaceFlags { bsd, target_os = "fuchsia", target_os = "linux", - target_os = "illumos", + solarish, ))] mod if_nameindex { use super::*; @@ -374,6 +354,6 @@ mod if_nameindex { bsd, target_os = "fuchsia", target_os = "linux", - target_os = "illumos", + solarish, ))] pub use if_nameindex::*; diff --git a/src/sys/ioctl/bsd.rs b/src/sys/ioctl/bsd.rs index 307994cb96..cedc8e63fe 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(target_os = "illumos"))] +#[cfg(not(solarish))] pub type ioctl_num_type = ::libc::c_ulong; #[doc(hidden)] -#[cfg(target_os = "illumos")] +#[cfg(solarish)] pub type ioctl_num_type = ::libc::c_int; /// The datatype used for the 3rd argument diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs index df222ec86c..e1e808f19e 100644 --- a/src/sys/ioctl/mod.rs +++ b/src/sys/ioctl/mod.rs @@ -234,11 +234,11 @@ mod linux; #[cfg(any(linux_android, target_os = "redox"))] pub use self::linux::*; -#[cfg(any(bsd, target_os = "illumos", target_os = "haiku",))] +#[cfg(any(bsd, solarish, target_os = "haiku",))] #[macro_use] mod bsd; -#[cfg(any(bsd, target_os = "illumos", target_os = "haiku",))] +#[cfg(any(bsd, solarish, target_os = "haiku",))] pub use self::bsd::*; /// Convert raw ioctl return value to a Nix result diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 94302484fb..60700ad8a2 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -31,7 +31,7 @@ feature! { pub mod fanotify; } -#[cfg(any(bsd, linux_android, target_os = "redox", target_os = "illumos"))] +#[cfg(any(bsd, linux_android, target_os = "redox", solarish))] #[cfg(feature = "ioctl")] #[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))] #[macro_use] @@ -88,7 +88,7 @@ feature! { #[cfg(not(any( target_os = "redox", target_os = "fuchsia", - target_os = "illumos", + solarish, target_os = "haiku" )))] feature! { @@ -182,7 +182,7 @@ feature! { #[cfg(all( any( target_os = "freebsd", - target_os = "illumos", + solarish, target_os = "linux", target_os = "netbsd" ), diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index eb1944bb99..608a6e5cc1 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1,7 +1,7 @@ #[cfg(any( bsd, linux_android, - target_os = "illumos", + solarish, target_os = "haiku", target_os = "fuchsia", target_os = "aix", @@ -230,7 +230,7 @@ pub enum AddressFamily { #[cfg(bsd)] Hylink = libc::AF_HYLINK, /// Link layer interface - #[cfg(any(bsd, target_os = "illumos"))] + #[cfg(any(bsd, solarish))] Link = libc::AF_LINK, /// connection-oriented IP, aka ST II #[cfg(bsd)] @@ -265,7 +265,7 @@ impl AddressFamily { libc::PF_ROUTE => Some(AddressFamily::Route), #[cfg(linux_android)] libc::AF_PACKET => Some(AddressFamily::Packet), - #[cfg(any(bsd, target_os = "illumos"))] + #[cfg(any(bsd, solarish))] libc::AF_LINK => Some(AddressFamily::Link), #[cfg(any(linux_android, apple_targets))] libc::AF_VSOCK => Some(AddressFamily::Vsock), @@ -506,7 +506,7 @@ impl UnixAddr { cfg_if! { if #[cfg(any(linux_android, target_os = "fuchsia", - target_os = "illumos", + solarish, target_os = "redox", ))] { @@ -547,7 +547,7 @@ impl SockaddrLike for UnixAddr { cfg_if! { if #[cfg(any(linux_android, target_os = "fuchsia", - target_os = "illumos", + solarish, target_os = "redox", ))] { let su_len = len.unwrap_or( @@ -577,7 +577,7 @@ impl SockaddrLike for UnixAddr { cfg_if! { if #[cfg(any(linux_android, target_os = "fuchsia", - target_os = "illumos", + solarish, target_os = "redox", ))] { self.sun_len = new_length as u8; @@ -1101,7 +1101,7 @@ impl SockaddrLike for SockaddrStorage { #[cfg(any( linux_android, target_os = "fuchsia", - target_os = "illumos", + solarish, ))] if i32::from(ss.ss_family) == libc::AF_UNIX { // Safe because we UnixAddr is strictly smaller than @@ -1131,7 +1131,7 @@ impl SockaddrLike for SockaddrStorage { libc::AF_INET6 => unsafe { SockaddrIn6::from_raw(addr, l).map(|sin6| Self { sin6 }) }, - #[cfg(any(bsd, target_os = "illumos", target_os = "haiku"))] + #[cfg(any(bsd, solarish, target_os = "haiku"))] #[cfg(feature = "net")] libc::AF_LINK => unsafe { LinkAddr::from_raw(addr, l).map(|dl| Self { dl }) @@ -1158,7 +1158,7 @@ impl SockaddrLike for SockaddrStorage { } } - #[cfg(any(linux_android, target_os = "fuchsia", target_os = "illumos"))] + #[cfg(any(linux_android, target_os = "fuchsia", solarish))] fn len(&self) -> libc::socklen_t { match self.as_unix_addr() { // The UnixAddr type knows its own length @@ -1219,7 +1219,7 @@ impl SockaddrStorage { cfg_if! { if #[cfg(any(linux_android, target_os = "fuchsia", - target_os = "illumos", + solarish, ))] { let p = unsafe{ &self.ss as *const libc::sockaddr_storage }; @@ -1248,7 +1248,7 @@ impl SockaddrStorage { cfg_if! { if #[cfg(any(linux_android, target_os = "fuchsia", - target_os = "illumos", + solarish, ))] { let p = unsafe{ &self.ss as *const libc::sockaddr_storage }; @@ -1282,7 +1282,7 @@ impl SockaddrStorage { as_link_addr, as_link_addr_mut, LinkAddr, AddressFamily::Packet, libc::sockaddr_ll, dl} - #[cfg(any(bsd, target_os = "illumos"))] + #[cfg(any(bsd, solarish))] #[cfg(feature = "net")] accessors! { as_link_addr, as_link_addr_mut, LinkAddr, @@ -1332,7 +1332,7 @@ impl fmt::Display for SockaddrStorage { libc::AF_INET => self.sin.fmt(f), #[cfg(feature = "net")] libc::AF_INET6 => self.sin6.fmt(f), - #[cfg(any(bsd, target_os = "illumos"))] + #[cfg(any(bsd, solarish))] #[cfg(feature = "net")] libc::AF_LINK => self.dl.fmt(f), #[cfg(linux_android)] @@ -1394,7 +1394,7 @@ impl Hash for SockaddrStorage { libc::AF_INET => self.sin.hash(s), #[cfg(feature = "net")] libc::AF_INET6 => self.sin6.hash(s), - #[cfg(any(bsd, target_os = "illumos"))] + #[cfg(any(bsd, solarish))] #[cfg(feature = "net")] libc::AF_LINK => self.dl.hash(s), #[cfg(linux_android)] @@ -1424,7 +1424,7 @@ impl PartialEq for SockaddrStorage { (libc::AF_INET, libc::AF_INET) => self.sin == other.sin, #[cfg(feature = "net")] (libc::AF_INET6, libc::AF_INET6) => self.sin6 == other.sin6, - #[cfg(any(bsd, target_os = "illumos"))] + #[cfg(any(bsd, solarish))] #[cfg(feature = "net")] (libc::AF_LINK, libc::AF_LINK) => self.dl == other.dl, #[cfg(linux_android)] @@ -1854,7 +1854,7 @@ mod datalink { } } -#[cfg(any(bsd, target_os = "illumos", target_os = "haiku", target_os = "aix"))] +#[cfg(any(bsd, solarish, target_os = "haiku", target_os = "aix"))] mod datalink { feature! { #![feature = "net"] @@ -2128,7 +2128,7 @@ mod tests { mod link { #![allow(clippy::cast_ptr_alignment)] - #[cfg(any(apple_targets, target_os = "illumos"))] + #[cfg(any(apple_targets, solarish))] use super::super::super::socklen_t; use super::*; @@ -2215,9 +2215,9 @@ mod tests { } } - #[cfg(target_os = "illumos")] + #[cfg(solarish)] #[test] - fn illumos_tap() { + fn solarish_tap() { let bytes = [25u8, 0, 0, 0, 6, 0, 6, 0, 24, 101, 144, 221, 76, 176]; let ptr = bytes.as_ptr(); let sa = ptr as *const libc::sockaddr; diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index a37e123616..85dac2cabc 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -256,13 +256,13 @@ libc_bitflags! { #[cfg(any(linux_android, freebsdlike, netbsdlike, - target_os = "illumos"))] + solarish))] SOCK_NONBLOCK; /// Set close-on-exec on the new descriptor #[cfg(any(linux_android, freebsdlike, netbsdlike, - target_os = "illumos"))] + solarish))] SOCK_CLOEXEC; /// Return `EPIPE` instead of raising `SIGPIPE` #[cfg(target_os = "netbsd")] @@ -343,8 +343,7 @@ libc_bitflags! { #[cfg(any(linux_android, netbsdlike, target_os = "fuchsia", - target_os = "freebsd", - target_os = "solaris"))] + target_os = "freebsd"))] MSG_WAITFORONE; } } @@ -2156,7 +2155,7 @@ pub fn accept(sockfd: RawFd) -> Result { netbsdlike, target_os = "emscripten", target_os = "fuchsia", - target_os = "illumos", + solarish, target_os = "linux", ))] pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result { diff --git a/src/sys/time.rs b/src/sys/time.rs index d5e9f3a6b2..ac13de419c 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -18,7 +18,7 @@ const fn zero_init_timespec() -> timespec { all( any( target_os = "freebsd", - target_os = "illumos", + solarish, target_os = "linux", target_os = "netbsd" ), @@ -97,7 +97,7 @@ pub(crate) mod timer { const TFD_TIMER_CANCEL_ON_SET = libc::TFD_TIMER_CANCEL_ON_SET; } } - #[cfg(any(freebsdlike, target_os = "netbsd", target_os = "illumos"))] + #[cfg(any(freebsdlike, target_os = "netbsd", solarish))] bitflags! { /// Flags that are used for arming the timer. #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] diff --git a/src/sys/uio.rs b/src/sys/uio.rs index 29e3647b35..cdf380dd11 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -53,7 +53,7 @@ pub fn readv(fd: Fd, iov: &mut [IoSliceMut<'_>]) -> Result { /// or an error occurs. The file offset is not changed. /// /// See also: [`writev`](fn.writev.html) and [`pwrite`](fn.pwrite.html) -#[cfg(not(any(target_os = "redox", target_os = "haiku")))] +#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris")))] pub fn pwritev( fd: Fd, iov: &[IoSlice<'_>], @@ -82,7 +82,7 @@ pub fn pwritev( /// changed. /// /// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html) -#[cfg(not(any(target_os = "redox", target_os = "haiku")))] +#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris")))] // Clippy doesn't know that we need to pass iov mutably only because the // mutation happens after converting iov to a pointer #[allow(clippy::needless_pass_by_ref_mut)] diff --git a/src/unistd.rs b/src/unistd.rs index a9d8b0aaf2..a86f54c504 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1647,7 +1647,7 @@ pub fn setgroups(groups: &[Gid]) -> Result<()> { /// will only ever return the complete list or else an error. #[cfg(not(any( target_os = "aix", - target_os = "illumos", + solarish, apple_targets, target_os = "redox" )))] @@ -3200,9 +3200,9 @@ impl From for libc::passwd { target_os = "haiku", )))] pw_expire: u.expire, - #[cfg(target_os = "illumos")] + #[cfg(solarish)] pw_age: CString::new("").unwrap().into_raw(), - #[cfg(target_os = "illumos")] + #[cfg(solarish)] pw_comment: CString::new("").unwrap().into_raw(), #[cfg(freebsdlike)] pw_fields: 0, diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index fe0a3bde07..d035a7bb04 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -140,7 +140,11 @@ fn test_pread() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "haiku")))] +#[cfg(not(any( + target_os = "redox", + target_os = "haiku", + target_os = "solaris" +)))] fn test_pwritev() { use std::io::Read; @@ -175,7 +179,11 @@ fn test_pwritev() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "haiku")))] +#[cfg(not(any( + target_os = "redox", + target_os = "haiku", + target_os = "solaris" +)))] fn test_preadv() { use std::io::Write; diff --git a/test/test.rs b/test/test.rs index eed532c194..388a0a42e8 100644 --- a/test/test.rs +++ b/test/test.rs @@ -52,7 +52,7 @@ mod test_time; #[cfg(all( any( target_os = "freebsd", - target_os = "illumos", + solarish, target_os = "linux", target_os = "netbsd" ), diff --git a/test/test_dir.rs b/test/test_dir.rs index 2af4aa5c0a..24ecd6963e 100644 --- a/test/test_dir.rs +++ b/test/test_dir.rs @@ -6,10 +6,10 @@ use tempfile::tempdir; #[cfg(test)] fn flags() -> OFlag { - #[cfg(target_os = "illumos")] + #[cfg(solarish)] let f = OFlag::O_RDONLY | OFlag::O_CLOEXEC; - #[cfg(not(target_os = "illumos"))] + #[cfg(not(solarish))] let f = OFlag::O_RDONLY | OFlag::O_CLOEXEC | OFlag::O_DIRECTORY; f diff --git a/test/test_pty.rs b/test/test_pty.rs index ae4127e481..368ec129b0 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -96,7 +96,7 @@ fn open_ptty_pair() -> (PtyMaster, File) { open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty()) .unwrap(); - #[cfg(target_os = "illumos")] + #[cfg(solarish)] // TODO: rewrite using ioctl! #[allow(clippy::comparison_chain)] { diff --git a/test/test_resource.rs b/test/test_resource.rs index 2ab581ba29..beae01c4c8 100644 --- a/test/test_resource.rs +++ b/test/test_resource.rs @@ -1,7 +1,7 @@ #[cfg(not(any( target_os = "redox", target_os = "fuchsia", - target_os = "illumos", + solarish, target_os = "haiku" )))] use nix::sys::resource::{getrlimit, setrlimit, Resource}; @@ -18,7 +18,7 @@ use nix::sys::resource::{getrlimit, setrlimit, Resource}; #[cfg(not(any( target_os = "redox", target_os = "fuchsia", - target_os = "illumos", + solarish, target_os = "haiku" )))] pub fn test_resource_limits_nofile() { diff --git a/test/test_stat.rs b/test/test_stat.rs index 6bae35e188..58238249d9 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -383,7 +383,7 @@ fn test_mknod() { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "illumos", + solarish, apple_targets, target_os = "haiku", target_os = "redox" diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 0a841df060..6e9e4f65c5 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -294,7 +294,7 @@ fn test_setgroups() { target_os = "redox", target_os = "fuchsia", target_os = "haiku", - target_os = "illumos" + solarish )))] fn test_initgroups() { // Skip this test when not run as root as `initgroups()` and `setgroups()` @@ -437,7 +437,7 @@ cfg_if! { // https://github.com/nix-rust/nix/issues/555 execve_test_factory!(test_execve, execve, CString::new("/bin/sh").unwrap().as_c_str()); execve_test_factory!(test_fexecve, fexecve, File::open("/bin/sh").unwrap().into_raw_fd()); - } else if #[cfg(any(target_os = "illumos", + } else if #[cfg(any(solarish, apple_targets, target_os = "netbsd", target_os = "openbsd", @@ -756,7 +756,7 @@ fn test_pipe() { target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", - target_os = "illumos", + solarish, target_os = "linux", target_os = "netbsd", target_os = "openbsd",