From 6fd74181586a4e2a2cfc24548e513775077df76b Mon Sep 17 00:00:00 2001 From: Aaron Drew Date: Tue, 10 Jan 2023 13:53:16 +1100 Subject: [PATCH 01/30] Fix endian swap on SocketAddrV6. flowinfo and scope_id should not be byte swapped. --- CHANGELOG.md | 9 +++++++++ src/sys/socket/addr.rs | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a332bc5f09..648f2d8104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [Unreleased] - ReleaseDate +### Added +### Changed +### Fixed +- Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering. + ([#1964](https://github.com/nix-rust/nix/pull/1964)) + +### Removed + ## [0.26.1] - 2022-11-29 ### Added ### Changed diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 8b23b10cf0..4e565a5b68 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1476,8 +1476,8 @@ impl From for net::SocketAddrV6 { net::SocketAddrV6::new( net::Ipv6Addr::from(addr.0.sin6_addr.s6_addr), u16::from_be(addr.0.sin6_port), - u32::from_be(addr.0.sin6_flowinfo), - u32::from_be(addr.0.sin6_scope_id), + addr.0.sin6_flowinfo, + addr.0.sin6_scope_id, ) } } @@ -3167,6 +3167,18 @@ mod tests { SockaddrIn6::size() as usize ); } + + #[test] + // Ensure that we can convert to-and-from std::net variants without change. + fn to_and_from() { + let s = "[1234:5678:90ab:cdef::1111:2222]:8080"; + let mut nix_sin6 = SockaddrIn6::from_str(s).unwrap(); + nix_sin6.0.sin6_flowinfo = 0x12345678; + nix_sin6.0.sin6_scope_id = 0x9abcdef0; + + let std_sin6 : std::net::SocketAddrV6 = nix_sin6.into(); + assert_eq!(nix_sin6, std_sin6.into()); + } } mod sockaddr_storage { From 975a3d5c7cdb6948944d86edddfc58dcad31fd2f Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 17 Jan 2023 14:19:16 -0700 Subject: [PATCH 02/30] Tidy up the CHANGELOG a bit. --- CHANGELOG.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 648f2d8104..dd14ec7005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,23 +4,15 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] - ReleaseDate -### Added -### Changed ### Fixed - Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering. ([#1964](https://github.com/nix-rust/nix/pull/1964)) -### Removed - ## [0.26.1] - 2022-11-29 -### Added -### Changed ### Fixed - Fix UB with `sys::socket::sockopt::SockType` using `SOCK_PACKET`. ([#1821](https://github.com/nix-rust/nix/pull/1821)) -### Removed - ## [0.26.0] - 2022-11-29 ### Added From 4a83f8b8b5ea93b0dd6e747ada37c5f588b230d5 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 3 Dec 2022 16:46:42 -0700 Subject: [PATCH 03/30] Drop x86_64-unknown-darwin to Tier 2 And promote aarch64-unknown-darwin to Tier 1. Because that's what Cirrus CI is doing. Fixes #1904 --- .cirrus.yml | 14 +++++++------- README.md | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index ab1178dd1a..1e073d707e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -67,13 +67,13 @@ task: - if [ -z "$NOHACK" ]; then cargo hack check --each-feature --target i686-unknown-freebsd; fi before_cache_script: rm -rf $CARGO_HOME/registry/index -# Test macOS x86_64 in a full VM +# Test macOS aarch64 in a full VM task: - name: macOS x86_64 + name: macOS aarch64 env: - TARGET: x86_64-apple-darwin - osx_instance: - image: big-sur-xcode + TARGET: aarch64-apple-darwin + macos_instance: + image: ghcr.io/cirruslabs/macos-ventura-base:latest setup_script: - curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs - sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN @@ -235,9 +235,9 @@ task: - name: Linux x32 env: TARGET: x86_64-unknown-linux-gnux32 - - name: macOS aarch64 + - name: macOS x86_64 env: - TARGET: aarch64-apple-darwin + TARGET: x86_64-apple-darwin - name: NetBSD x86_64 env: TARGET: x86_64-unknown-netbsd diff --git a/README.md b/README.md index 7597ba0afc..2c42b905f7 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ limitations. Support for platforms is split into three tiers: The following targets are supported by `nix`: Tier 1: + * aarch64-apple-darwin * aarch64-unknown-linux-gnu * arm-unknown-linux-gnueabi * armv7-unknown-linux-gnueabihf @@ -58,13 +59,11 @@ Tier 1: * mips64el-unknown-linux-gnuabi64 * mipsel-unknown-linux-gnu * powerpc64le-unknown-linux-gnu - * x86_64-apple-darwin * x86_64-unknown-freebsd * x86_64-unknown-linux-gnu * x86_64-unknown-linux-musl Tier 2: - * aarch64-apple-darwin * aarch64-apple-ios * aarch64-linux-android * arm-linux-androideabi @@ -75,6 +74,7 @@ Tier 2: * s390x-unknown-linux-gnu * x86_64-apple-ios * x86_64-linux-android + * x86_64-apple-darwin * x86_64-unknown-illumos * x86_64-unknown-netbsd From 8aa85bbf2743ab30a329e86b548d2744bb2383df Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 31 Dec 2022 23:16:46 +0000 Subject: [PATCH 04/30] fix: clippy::size_of_ref --- src/sys/socket/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 2d7159a63a..8513b6fbe7 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1298,7 +1298,7 @@ impl<'a> ControlMessage<'a> { } #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::AlgSetIv(iv) => { - mem::size_of_val(&iv) + iv.len() + mem::size_of::<&[u8]>() + iv.len() }, #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::AlgSetOp(op) => { From 1e3f062fd842b7ce130ea6c792a8eab7f78f82e3 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 17 Jan 2023 17:09:07 -0700 Subject: [PATCH 05/30] (cargo-release) version 0.26.2 --- CHANGELOG.md | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd14ec7005..283cb86a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). -## [Unreleased] - ReleaseDate +## [0.26.2] - 2023-01-18 ### Fixed - Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering. ([#1964](https://github.com/nix-rust/nix/pull/1964)) diff --git a/Cargo.toml b/Cargo.toml index cfe20d8297..8b1d873186 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "nix" description = "Rust friendly bindings to *nix APIs" edition = "2018" -version = "0.26.1" +version = "0.26.2" rust-version = "1.56" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix" From d34cf6aa55bc1b1845d1ea86db36e161b35bf8df Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 26 Aug 2023 17:56:11 -0600 Subject: [PATCH 06/30] Start a CHANGELOG for r0.26.3 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 283cb86a36..e8cdd97672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [Unreleased] - ReleaseDate + +### Fixed + ## [0.26.2] - 2023-01-18 ### Fixed - Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering. From 4f80a18bc5ded8e489112791eb8403decd97e2cf Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Tue, 21 Mar 2023 02:24:29 +0000 Subject: [PATCH 07/30] Merge #1925 1925: fix: send ETH_P_ALL in htons format r=asomers a=tzneal Co-authored-by: Todd Neal --- src/sys/socket/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 8513b6fbe7..23ecc164a7 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -226,7 +226,7 @@ pub enum SockProtocol { // The protocol number is fed into the socket syscall in network byte order. #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg_attr(docsrs, doc(cfg(all())))] - EthAll = libc::ETH_P_ALL.to_be(), + EthAll = (libc::ETH_P_ALL as u16).to_be() as i32, } #[cfg(any(target_os = "linux"))] From 05eee293a2dcce166ac20f72d037a7d8db3737ef Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Mon, 17 Jul 2023 22:26:39 +0000 Subject: [PATCH 08/30] Merge #2041 2041: Set the length of a socket address when calling `recvmsg` on Linux r=asomers a=JarredAllen # Background I think I've found a bug with `recvmsg` on Linux where it doesn't set the length of a received socket address. I found this while working with unix datagram sockets with path `struct sockaddr_un` addresses, but I think this applies to any variable-length socket address type. At present, the `sun_len` field of `UnixAddr` on Linux shows up as 0 whenever I call `recvmsg`. I think it's reading uninitialized memory (afaict the `recvmsg` function never initializes it before we call `MaybeUninit::assume_init`), though it's possible that it's being zero-initialized somewhere that I missed. Either way, this isn't the correct behavior, which should set it to the length of the `struct sockaddr_un` contents (or whatever other type of socket). # Changes I changed the `recvmsg` function to construct the returned socket address from the `struct sockaddr` and length returned by the libc `recvmsg` call (using the `from_raw` function the trait provides). Since the trait is sealed so downstream crates can't implement it, I believe this shouldn't be a breaking change. # Validation I've tested that my code (which failed due to this bug) now works. I also added a new test case which tests that we construct `UnixAddr`s correctly in the `recvmsg` function, which passes locally for me and fails if I cherry-pick it onto the current `master`. I've also checked that `cargo test` and `cargo clippy` both still pass on `aarch64-apple-darwin` and on `aarch64-unknown-linux-musl` targets (the two targets I develop for/have access to). Hopefully your CI will confirm that everything else still works. Co-authored-by: Jarred Allen Co-authored-by: Jarred Allen --- CHANGELOG.md | 11 +++++++++ src/sys/socket/addr.rs | 53 +++++++++++++++++++++++++++++++++++++++-- src/sys/socket/mod.rs | 11 ++++++--- test/sys/test_socket.rs | 43 +++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8cdd97672..e3e3af1919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] - ReleaseDate ### Fixed +- Fix: send `ETH_P_ALL` in htons format + ([#1925](https://github.com/nix-rust/nix/pull/1925)) +- Fix: `recvmsg` now sets the length of the received `sockaddr_un` field + correctly on Linux platforms. ([#2041](https://github.com/nix-rust/nix/pull/2041)) +- Fix potentially invalid conversions in + `SockaddrIn::from`, + `SockaddrIn6::from`, `IpMembershipRequest::new`, and + `Ipv6MembershipRequest::new` with future Rust versions. + ([#2061](https://github.com/nix-rust/nix/pull/2061)) +- Fixed an incorrect lifetime returned from `recvmsg`. + ([#2095](https://github.com/nix-rust/nix/pull/2095)) ## [0.26.2] - 2023-01-18 ### Fixed diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 4e565a5b68..6f2e9eb31e 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1049,6 +1049,22 @@ impl SockaddrLike for UnixAddr { { mem::size_of::() as libc::socklen_t } + + unsafe fn set_length(&mut self, new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { + // `new_length` is only used on some platforms, so it must be provided even when not used + #![allow(unused_variables)] + cfg_if! { + if #[cfg(any(target_os = "android", + target_os = "fuchsia", + target_os = "illumos", + target_os = "linux", + target_os = "redox", + ))] { + self.sun_len = new_length as u8; + } + }; + Ok(()) + } } impl AsRef for UnixAddr { @@ -1198,7 +1214,32 @@ pub trait SockaddrLike: private::SockaddrLikePriv { { mem::size_of::() as libc::socklen_t } + + /// Set the length of this socket address + /// + /// This method may only be called on socket addresses whose lengths are dynamic, and it + /// returns an error if called on a type whose length is static. + /// + /// # Safety + /// + /// `new_length` must be a valid length for this type of address. Specifically, reads of that + /// length from `self` must be valid. + #[doc(hidden)] + unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { + Err(SocketAddressLengthNotDynamic) + } +} + +/// The error returned by [`SockaddrLike::set_length`] on an address whose length is statically +/// fixed. +#[derive(Copy, Clone, Debug)] +pub struct SocketAddressLengthNotDynamic; +impl fmt::Display for SocketAddressLengthNotDynamic { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("Attempted to set length on socket whose length is statically fixed") + } } +impl std::error::Error for SocketAddressLengthNotDynamic {} impl private::SockaddrLikePriv for () { fn as_mut_ptr(&mut self) -> *mut libc::sockaddr { @@ -1645,6 +1686,15 @@ impl SockaddrLike for SockaddrStorage { None => mem::size_of_val(self) as libc::socklen_t } } + + unsafe fn set_length(&mut self, new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { + match self.as_unix_addr_mut() { + Some(addr) => { + addr.set_length(new_length) + }, + None => Err(SocketAddressLengthNotDynamic), + } + } } macro_rules! accessors { @@ -1961,7 +2011,7 @@ impl PartialEq for SockaddrStorage { } } -mod private { +pub(super) mod private { pub trait SockaddrLikePriv { /// Returns a mutable raw pointer to the inner structure. /// @@ -2850,7 +2900,6 @@ mod datalink { &self.0 } } - } } diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 23ecc164a7..997e265823 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1611,7 +1611,7 @@ impl MultiHeaders { { // we will be storing pointers to addresses inside mhdr - convert it into boxed // slice so it can'be changed later by pushing anything into self.addresses - let mut addresses = vec![std::mem::MaybeUninit::uninit(); num_slices].into_boxed_slice(); + let mut addresses = vec![std::mem::MaybeUninit::::uninit(); num_slices].into_boxed_slice(); let msg_controllen = cmsg_buffer.as_ref().map_or(0, |v| v.capacity()); @@ -1916,7 +1916,7 @@ unsafe fn read_mhdr<'a, 'i, S>( mhdr: msghdr, r: isize, msg_controllen: usize, - address: S, + mut address: S, ) -> RecvMsg<'a, 'i, S> where S: SockaddrLike { @@ -1932,6 +1932,11 @@ unsafe fn read_mhdr<'a, 'i, S>( }.as_ref() }; + // Ignore errors if this socket address has statically-known length + // + // This is to ensure that unix socket addresses have their length set appropriately. + let _ = address.set_length(mhdr.msg_namelen as usize); + RecvMsg { bytes: r as usize, cmsghdr, @@ -1967,7 +1972,7 @@ unsafe fn pack_mhdr_to_receive( // initialize it. let mut mhdr = mem::MaybeUninit::::zeroed(); let p = mhdr.as_mut_ptr(); - (*p).msg_name = (*address).as_mut_ptr() as *mut c_void; + (*p).msg_name = address as *mut c_void; (*p).msg_namelen = S::size(); (*p).msg_iov = iov_buffer as *mut iovec; (*p).msg_iovlen = iov_buffer_len as _; diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 5adc77ed6b..337c8dc0af 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -298,6 +298,49 @@ pub fn test_socketpair() { assert_eq!(&buf[..], b"hello"); } +#[test] +pub fn test_recvmsg_sockaddr_un() { + use nix::sys::socket::{ + self, bind, socket, AddressFamily, MsgFlags, SockFlag, SockType, + }; + + let tempdir = tempfile::tempdir().unwrap(); + let sockname = tempdir.path().join("sock"); + let sock = socket( + AddressFamily::Unix, + SockType::Datagram, + SockFlag::empty(), + None, + ) + .expect("socket failed"); + let sockaddr = UnixAddr::new(&sockname).unwrap(); + bind(sock, &sockaddr).expect("bind failed"); + + // Send a message + let send_buffer = "hello".as_bytes(); + if let Err(e) = socket::sendmsg( + sock, + &[std::io::IoSlice::new(send_buffer)], + &[], + MsgFlags::empty(), + Some(&sockaddr), + ) { + crate::skip!("Couldn't send ({:?}), so skipping test", e); + } + + // Receive the message + let mut recv_buffer = [0u8; 32]; + let received = socket::recvmsg( + sock, + &mut [std::io::IoSliceMut::new(&mut recv_buffer)], + None, + MsgFlags::empty(), + ) + .unwrap(); + // Check the address in the received message + assert_eq!(sockaddr, received.address.unwrap()); +} + #[test] pub fn test_std_conversions() { use nix::sys::socket::*; From cedf7a1f19cd31d4f15263c4b5197e141ad1458e Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:54:08 +0000 Subject: [PATCH 09/30] Merge #2061 2061: For invalid IP address conversions with future Rust versions r=asomers a=asomers Rust's standard library no longer guarantees that Ipv4Addr and Ipv6Addr are wrappers around the C types (though for now at least, they are identical on all platforms I'm aware of). So do the conversions explicitly instead of transmuting. Fixes #2053 Co-authored-by: Alan Somers --- Cargo.toml | 1 - src/sys/socket/addr.rs | 16 ++++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b1d873186..acb03363bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,6 @@ libc = { version = "0.2.137", features = [ "extra_traits" ] } bitflags = "1.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } -static_assertions = "1" [target.'cfg(not(target_os = "redox"))'.dependencies] memoffset = { version = "0.7", optional = true } diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 6f2e9eb31e..6ae657f493 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -41,21 +41,16 @@ use std::{fmt, mem, net, ptr, slice}; /// Convert a std::net::Ipv4Addr into the libc form. #[cfg(feature = "net")] pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr { - static_assertions::assert_eq_size!(net::Ipv4Addr, libc::in_addr); - // Safe because both types have the same memory layout, and no fancy Drop - // impls. - unsafe { - mem::transmute(addr) + libc::in_addr { + s_addr: u32::from_ne_bytes(addr.octets()) } } /// Convert a std::net::Ipv6Addr into the libc form. #[cfg(feature = "net")] pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr { - static_assertions::assert_eq_size!(net::Ipv6Addr, libc::in6_addr); - // Safe because both are Newtype wrappers around the same libc type - unsafe { - mem::transmute(*addr) + libc::in6_addr { + s6_addr: addr.octets() } } @@ -1276,9 +1271,6 @@ impl SockaddrLike for () { } /// An IPv4 socket address -// This is identical to net::SocketAddrV4. But the standard library -// doesn't allow direct access to the libc fields, which we need. So we -// reimplement it here. #[cfg(feature = "net")] #[repr(transparent)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] From a992fb1901e0e7aacb11b62b0b5526df4f9bfc34 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 19 Aug 2023 02:57:36 +0000 Subject: [PATCH 10/30] Merge pull request #2095 from asomers/recvmsg-lifetime Fix an incorrect lifetime in the return value of recvmsg --- src/sys/socket/mod.rs | 2 +- test/sys/test_socket.rs | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 997e265823..e4f3fbc4c5 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -2051,7 +2051,7 @@ fn pack_mhdr_to_send<'a, I, C, S>( /// [recvmsg(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html) pub fn recvmsg<'a, 'outer, 'inner, S>(fd: RawFd, iov: &'outer mut [IoSliceMut<'inner>], mut cmsg_buffer: Option<&'a mut Vec>, - flags: MsgFlags) -> Result> + flags: MsgFlags) -> Result> where S: SockaddrLike + 'a, 'inner: 'outer { diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 337c8dc0af..9db5236816 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -330,13 +330,9 @@ pub fn test_recvmsg_sockaddr_un() { // Receive the message let mut recv_buffer = [0u8; 32]; - let received = socket::recvmsg( - sock, - &mut [std::io::IoSliceMut::new(&mut recv_buffer)], - None, - MsgFlags::empty(), - ) - .unwrap(); + let mut iov = [std::io::IoSliceMut::new(&mut recv_buffer)]; + let received = + socket::recvmsg(sock, &mut iov, None, MsgFlags::empty()).unwrap(); // Check the address in the received message assert_eq!(sockaddr, received.address.unwrap()); } From df3c7a6cb4080e2239bf0d33d928c9c657520c5b Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Tue, 9 May 2023 19:08:17 +0000 Subject: [PATCH 11/30] Merge #2033 2033: remove unused mut from two variable declarations in sys/socket/mod.rs r=asomers a=inglorion This addresses diagnostics like: error: variable does not need to be mutable --> src/sys/socket/mod.rs:1537:13 | 1537 | let mut p = &mut mmsghdr.msg_hdr; Co-authored-by: Bob Haarman --- src/sys/socket/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index e4f3fbc4c5..7908cd96c1 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1535,7 +1535,7 @@ pub fn sendmmsg<'a, XS, AS, C, I, S>( for (i, ((slice, addr), mmsghdr)) in slices.into_iter().zip(addrs.as_ref()).zip(data.items.iter_mut() ).enumerate() { - let mut p = &mut mmsghdr.msg_hdr; + let p = &mut mmsghdr.msg_hdr; p.msg_iov = slice.as_ref().as_ptr() as *mut libc::iovec; p.msg_iovlen = slice.as_ref().len() as _; @@ -1689,7 +1689,7 @@ where { let mut count = 0; for (i, (slice, mmsghdr)) in slices.into_iter().zip(data.items.iter_mut()).enumerate() { - let mut p = &mut mmsghdr.msg_hdr; + let p = &mut mmsghdr.msg_hdr; p.msg_iov = slice.as_ref().as_ptr() as *mut libc::iovec; p.msg_iovlen = slice.as_ref().len() as _; count = i + 1; From 56d027f40c6a7417f15ec3ca88442a52ef77650e Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 26 Aug 2023 18:08:27 -0600 Subject: [PATCH 12/30] Fix a clippy::needless_pass_by_ref_mut warning This is a direct commit to the r0.26 branch, because the offending code has been removed in master. --- src/sys/uio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/uio.rs b/src/sys/uio.rs index b31c3068a7..ea9d214d21 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -201,7 +201,7 @@ impl<'a> IoVec<&'a mut [u8]> { pub fn from_mut_slice(buf: &'a mut [u8]) -> IoVec<&'a mut [u8]> { IoVec( libc::iovec { - iov_base: buf.as_ptr() as *mut c_void, + iov_base: buf.as_mut_ptr() as *mut c_void, iov_len: buf.len() as size_t, }, PhantomData, From 6d857129ad2d0ce5e8388b00676e70aecdebd87d Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Sun, 6 Aug 2023 19:34:43 +0000 Subject: [PATCH 13/30] Merge #2086 2086: Clippy cleanup r=asomers a=asomers Clippy found some const-correctness issues in internal APIs, but nothing user-facing. Co-authored-by: Alan Somers --- .cirrus.yml | 5 ++++- Cargo.toml | 4 +++- src/dir.rs | 3 +++ src/sys/socket/mod.rs | 22 +++++++++++----------- src/sys/uio.rs | 6 ++++++ 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 1e073d707e..4f97ec5822 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -5,6 +5,7 @@ cargo_cache: env: # Build by default; don't just check BUILD: build + CLIPPYFLAGS: -D warnings -A unknown-lints RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings TOOL: cargo @@ -20,7 +21,7 @@ build: &BUILD - rustc +$TOOLCHAIN -Vv - $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets - $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET - - $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- -D warnings + - $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- $CLIPPYFLAGS - if [ -z "$NOHACK" ]; then mkdir -p $HOME/.cargo/bin; export PATH=$HOME/.cargo/bin:$PATH; fi - if [ -z "$NOHACK" ]; then curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-${HOST:-$TARGET}.tar.gz | tar xzf - -C ~/.cargo/bin; fi - if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN hack $ZFLAGS check --target $TARGET --each-feature; fi @@ -259,6 +260,7 @@ task: TARGET: x86_64-unknown-redox # Redox's MSRV policy is unclear. Until they define it, use nightly. TOOLCHAIN: nightly + CLIPPYFLAGS: -D warnings setup_script: - rustup target add $TARGET - rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET @@ -275,6 +277,7 @@ task: HOST: x86_64-unknown-linux-gnu TOOLCHAIN: nightly ZFLAGS: -Zbuild-std + CLIPPYFLAGS: -D warnings matrix: - name: DragonFly BSD x86_64 env: diff --git a/Cargo.toml b/Cargo.toml index acb03363bc..a51ccbe254 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,9 @@ assert-impl = "0.1" lazy_static = "1.4" parking_lot = "0.12" rand = "0.8" -tempfile = "3.3.0" +# tempfile 3.7.0 doesn't build on Haiku +# https://github.com/Stebalien/tempfile/issues/246 +tempfile = ">=3.3.0, < 3.7.0" semver = "1.0.7" [target.'cfg(any(target_os = "android", target_os = "linux"))'.dev-dependencies] diff --git a/src/dir.rs b/src/dir.rs index 5ce503644e..ad10ce16e7 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -101,6 +101,9 @@ impl Drop for Dir { } } +// The pass by mut is technically needless only because the inner NonNull is +// Copy. But philosophically we're mutating the Dir, so we pass by mut. +#[allow(clippy::needless_pass_by_ref_mut)] fn next(dir: &mut Dir) -> Option> { unsafe { // Note: POSIX specifies that portable applications should dynamically allocate a diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 7908cd96c1..a8f2c034c5 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1617,18 +1617,18 @@ impl MultiHeaders { // we'll need a cmsg_buffer for each slice, we preallocate a vector and split // it into "slices" parts - let cmsg_buffers = + let mut cmsg_buffers = cmsg_buffer.map(|v| vec![0u8; v.capacity() * num_slices].into_boxed_slice()); let items = addresses .iter_mut() .enumerate() .map(|(ix, address)| { - let (ptr, cap) = match &cmsg_buffers { - Some(v) => ((&v[ix * msg_controllen] as *const u8), msg_controllen), - None => (std::ptr::null(), 0), + let (ptr, cap) = match &mut cmsg_buffers { + Some(v) => ((&mut v[ix * msg_controllen] as *mut u8), msg_controllen), + None => (std::ptr::null_mut(), 0), }; - let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null(), 0, ptr, cap, address.as_mut_ptr()) }; + let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null_mut(), 0, ptr, cap, address.as_mut_ptr()) }; libc::mmsghdr { msg_hdr, msg_len: 0, @@ -1959,9 +1959,9 @@ unsafe fn read_mhdr<'a, 'i, S>( /// /// Buffers must remain valid for the whole lifetime of msghdr unsafe fn pack_mhdr_to_receive( - iov_buffer: *const IoSliceMut, + iov_buffer: *mut IoSliceMut, iov_buffer_len: usize, - cmsg_buffer: *const u8, + cmsg_buffer: *mut u8, cmsg_capacity: usize, address: *mut S, ) -> msghdr @@ -1997,7 +1997,7 @@ fn pack_mhdr_to_send<'a, I, C, S>( // The message header must be initialized before the individual cmsgs. let cmsg_ptr = if capacity > 0 { - cmsg_buffer.as_ptr() as *mut c_void + cmsg_buffer.as_mut_ptr() as *mut c_void } else { ptr::null_mut() }; @@ -2061,7 +2061,7 @@ pub fn recvmsg<'a, 'outer, 'inner, S>(fd: RawFd, iov: &'outer mut [IoSliceMut<'i .map(|v| (v.as_mut_ptr(), v.capacity())) .unwrap_or((ptr::null_mut(), 0)); let mut mhdr = unsafe { - pack_mhdr_to_receive(iov.as_ref().as_ptr(), iov.len(), msg_control, msg_controllen, address.as_mut_ptr()) + pack_mhdr_to_receive(iov.as_mut().as_mut_ptr(), iov.len(), msg_control, msg_controllen, address.as_mut_ptr()) }; let ret = unsafe { libc::recvmsg(fd, &mut mhdr, flags.bits()) }; @@ -2207,7 +2207,7 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result { unsafe { let ret = libc::recv( sockfd, - buf.as_ptr() as *mut c_void, + buf.as_mut_ptr() as *mut c_void, buf.len() as size_t, flags.bits(), ); @@ -2231,7 +2231,7 @@ pub fn recvfrom( let ret = Errno::result(libc::recvfrom( sockfd, - buf.as_ptr() as *mut c_void, + buf.as_mut_ptr() as *mut c_void, buf.len() as size_t, 0, addr.as_mut_ptr() as *mut libc::sockaddr, diff --git a/src/sys/uio.rs b/src/sys/uio.rs index ea9d214d21..c96ade37ff 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -28,6 +28,9 @@ pub fn writev(fd: RawFd, iov: &[IoSlice<'_>]) -> Result { /// Low-level vectored read from a raw file descriptor /// /// See also [readv(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html) +// 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)] pub fn readv(fd: RawFd, iov: &mut [IoSliceMut<'_>]) -> Result { // SAFETY: same as in writev(), IoSliceMut is ABI-compatible with iovec let res = unsafe { @@ -71,6 +74,9 @@ pub fn pwritev(fd: RawFd, iov: &[IoSlice<'_>], offset: off_t) -> Result { /// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html) #[cfg(not(any(target_os = "redox", target_os = "haiku")))] #[cfg_attr(docsrs, doc(cfg(all())))] +// 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)] pub fn preadv( fd: RawFd, iov: &mut [IoSliceMut<'_>], From 0c3afc27d7bdbea7e5c12969e1ba0607c14b1dc9 Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:25:58 +0000 Subject: [PATCH 14/30] Merge #2027 #2057 2027: Update to bitflags 2.2.1. r=asomers a=qwandor This is a new major version and requires some code changes. 2057: Haiku: `speed_t` is defined as `u8` for 32 and 64 bit systems r=asomers a=nielx This fixes the build on 32 bit Haiku systems. Co-authored-by: Andrew Walbran Co-authored-by: Niels Sascha Reedijk --- Cargo.toml | 2 +- src/macros.rs | 2 ++ src/mount/bsd.rs | 4 ++-- src/mount/linux.rs | 4 ++-- src/mqueue.rs | 2 +- src/sys/event.rs | 4 ++-- src/sys/stat.rs | 4 ++-- src/sys/statvfs.rs | 1 - src/sys/termios.rs | 6 +++--- src/sys/time.rs | 2 ++ src/unistd.rs | 4 ++-- 11 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a51ccbe254..08c7712874 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ targets = [ [dependencies] libc = { version = "0.2.137", features = [ "extra_traits" ] } -bitflags = "1.1" +bitflags = "2.3.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } diff --git a/src/macros.rs b/src/macros.rs index 99e0de8866..2514b042c8 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -63,6 +63,8 @@ macro_rules! libc_bitflags { } ) => { ::bitflags::bitflags! { + #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] + #[repr(transparent)] $(#[$outer])* pub struct $BitFlags: $T { $( diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs index d124f1f9ab..dbff654112 100644 --- a/src/mount/bsd.rs +++ b/src/mount/bsd.rs @@ -392,7 +392,7 @@ impl<'a> Nmount<'a> { let niov = self.iov.len() as c_uint; let iovp = self.iov.as_mut_ptr() as *mut libc::iovec; - let res = unsafe { libc::nmount(iovp, niov, flags.bits) }; + let res = unsafe { libc::nmount(iovp, niov, flags.bits()) }; match Errno::result(res) { Ok(_) => Ok(()), Err(error) => { @@ -446,7 +446,7 @@ where P: ?Sized + NixPath, { let res = mountpoint.with_nix_path(|cstr| unsafe { - libc::unmount(cstr.as_ptr(), flags.bits) + libc::unmount(cstr.as_ptr(), flags.bits()) })?; Errno::result(res).map(drop) diff --git a/src/mount/linux.rs b/src/mount/linux.rs index cf6a60b017..197854cc93 100644 --- a/src/mount/linux.rs +++ b/src/mount/linux.rs @@ -88,7 +88,7 @@ pub fn mount< s, t.as_ptr(), ty, - flags.bits, + flags.bits(), d as *const libc::c_void, ) }) @@ -108,7 +108,7 @@ pub fn umount(target: &P) -> Result<()> { pub fn umount2(target: &P, flags: MntFlags) -> Result<()> { let res = target.with_nix_path(|cstr| unsafe { - libc::umount2(cstr.as_ptr(), flags.bits) + libc::umount2(cstr.as_ptr(), flags.bits()) })?; Errno::result(res).map(drop) diff --git a/src/mqueue.rs b/src/mqueue.rs index 33599bf91d..cf8e725b3b 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -139,7 +139,7 @@ impl MqAttr { /// Open a message queue /// /// See also [`mq_open(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html) -// The mode.bits cast is only lossless on some OSes +// The mode.bits() cast is only lossless on some OSes #[allow(clippy::cast_lossless)] pub fn mq_open( name: &CStr, diff --git a/src/sys/event.rs b/src/sys/event.rs index d8ad628ea2..2cbb28d602 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -26,7 +26,7 @@ pub struct KEvent { target_os = "openbsd" ))] type type_of_udata = *mut libc::c_void; -#[cfg(any(target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] type type_of_udata = intptr_t; #[cfg(target_os = "netbsd")] @@ -87,7 +87,7 @@ libc_enum! { target_os = "openbsd" ))] pub type type_of_event_flag = u16; -#[cfg(any(target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] pub type type_of_event_flag = u32; libc_bitflags! { pub struct EventFlag: type_of_event_flag { diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 78203bfbe3..7e51c03a3f 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -177,7 +177,7 @@ pub fn mknod( dev: dev_t, ) -> Result<()> { let res = path.with_nix_path(|cstr| unsafe { - libc::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev) + libc::mknod(cstr.as_ptr(), kind.bits() | perm.bits() as mode_t, dev) })?; Errno::result(res).map(drop) @@ -202,7 +202,7 @@ pub fn mknodat( libc::mknodat( dirfd, cstr.as_ptr(), - kind.bits | perm.bits() as mode_t, + kind.bits() | perm.bits() as mode_t, dev, ) })?; diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs index 8de369f421..5eaa7c1aef 100644 --- a/src/sys/statvfs.rs +++ b/src/sys/statvfs.rs @@ -12,7 +12,6 @@ use crate::{errno::Errno, NixPath, Result}; #[cfg(not(target_os = "redox"))] libc_bitflags!( /// File system mount Flags - #[repr(C)] #[derive(Default)] pub struct FsFlags: c_ulong { /// Read Only diff --git a/src/sys/termios.rs b/src/sys/termios.rs index fba2cd8268..e59c7a363e 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -309,7 +309,7 @@ impl Termios { let termios = *self.inner.borrow_mut(); self.input_flags = InputFlags::from_bits_truncate(termios.c_iflag); self.output_flags = OutputFlags::from_bits_truncate(termios.c_oflag); - self.control_flags = ControlFlags::from_bits_truncate(termios.c_cflag); + self.control_flags = ControlFlags::from_bits_retain(termios.c_cflag); self.local_flags = LocalFlags::from_bits_truncate(termios.c_lflag); self.control_chars = termios.c_cc; #[cfg(any( @@ -355,9 +355,9 @@ libc_enum! { /// enum. /// /// B0 is special and will disable the port. - #[cfg_attr(all(any(target_os = "haiku"), target_pointer_width = "64"), repr(u8))] + #[cfg_attr(target_os = "haiku", repr(u8))] #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64"), repr(u64))] - #[cfg_attr(not(all(any(target_os = "ios", target_os = "macos", target_os = "haiku"), target_pointer_width = "64")), repr(u32))] + #[cfg_attr(all(not(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64")), not(target_os = "haiku")), repr(u32))] #[non_exhaustive] pub enum BaudRate { B0, diff --git a/src/sys/time.rs b/src/sys/time.rs index 0042c45084..5cabe2962a 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -91,6 +91,7 @@ pub(crate) mod timer { #[cfg(any(target_os = "android", target_os = "linux"))] bitflags! { /// Flags that are used for arming the timer. + #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct TimerSetTimeFlags: libc::c_int { const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME; } @@ -103,6 +104,7 @@ pub(crate) mod timer { ))] bitflags! { /// Flags that are used for arming the timer. + #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct TimerSetTimeFlags: libc::c_int { const TFD_TIMER_ABSTIME = libc::TIMER_ABSTIME; } diff --git a/src/unistd.rs b/src/unistd.rs index ca07b34a2e..14ca84369d 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -2906,7 +2906,7 @@ feature! { pub fn access(path: &P, amode: AccessFlags) -> Result<()> { let res = path.with_nix_path(|cstr| { unsafe { - libc::access(cstr.as_ptr(), amode.bits) + libc::access(cstr.as_ptr(), amode.bits()) } })?; Errno::result(res).map(drop) @@ -2947,7 +2947,7 @@ pub fn faccessat(dirfd: Option, path: &P, mode: Acce pub fn eaccess(path: &P, mode: AccessFlags) -> Result<()> { let res = path.with_nix_path(|cstr| { unsafe { - libc::eaccess(cstr.as_ptr(), mode.bits) + libc::eaccess(cstr.as_ptr(), mode.bits()) } })?; Errno::result(res).map(drop) From a67007d4a6e47890133bf8c62efe51a745e98529 Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Sat, 15 Jul 2023 18:45:19 +0000 Subject: [PATCH 15/30] Merge #2076 2076: Clippy cleanup r=asomers a=asomers Co-authored-by: Alan Somers --- src/mount/bsd.rs | 2 +- src/sys/socket/addr.rs | 3 +++ src/sys/socket/mod.rs | 2 +- test/test_fcntl.rs | 2 +- test/test_sendfile.rs | 8 ++++---- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs index dbff654112..6ed2dc7fbf 100644 --- a/src/mount/bsd.rs +++ b/src/mount/bsd.rs @@ -391,7 +391,7 @@ impl<'a> Nmount<'a> { }); let niov = self.iov.len() as c_uint; - let iovp = self.iov.as_mut_ptr() as *mut libc::iovec; + let iovp = self.iov.as_mut_ptr(); let res = unsafe { libc::nmount(iovp, niov, flags.bits()) }; match Errno::result(res) { Ok(_) => Ok(()), diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 6ae657f493..2f30bff464 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -770,6 +770,7 @@ enum UnixAddrKind<'a> { } impl<'a> UnixAddrKind<'a> { /// Safety: sun & sun_len must be valid + #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms unsafe fn get(sun: &'a libc::sockaddr_un, sun_len: u8) -> Self { assert!(sun_len as usize >= offset_of!(libc::sockaddr_un, sun_path)); let path_len = @@ -806,6 +807,7 @@ impl<'a> UnixAddrKind<'a> { impl UnixAddr { /// Create a new sockaddr_un representing a filesystem path. + #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms pub fn new(path: &P) -> Result { path.with_nix_path(|cstr| unsafe { let mut ret = libc::sockaddr_un { @@ -853,6 +855,7 @@ impl UnixAddr { /// processes to communicate with processes having a different filesystem view. #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg_attr(docsrs, doc(cfg(all())))] + #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms pub fn new_abstract(path: &[u8]) -> Result { unsafe { let mut ret = libc::sockaddr_un { diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index a8f2c034c5..6b6441ed88 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -2241,7 +2241,7 @@ pub fn recvfrom( Ok(( ret, T::from_raw( - addr.assume_init().as_ptr() as *const libc::sockaddr, + addr.assume_init().as_ptr(), Some(len), ), )) diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index e51044a069..383fde8f2d 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -340,7 +340,7 @@ mod linux_android { let buf1 = b"abcdef"; let buf2 = b"defghi"; - let iovecs = vec![IoSlice::new(&buf1[0..3]), IoSlice::new(&buf2[0..3])]; + let iovecs = [IoSlice::new(&buf1[0..3]), IoSlice::new(&buf2[0..3])]; let res = vmsplice(wr, &iovecs[..], SpliceFFlags::empty()).unwrap(); diff --git a/test/test_sendfile.rs b/test/test_sendfile.rs index f73a3b56c3..f442a0cab0 100644 --- a/test/test_sendfile.rs +++ b/test/test_sendfile.rs @@ -63,10 +63,10 @@ fn test_sendfile64_linux() { fn test_sendfile_freebsd() { // Declare the content let header_strings = - vec!["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; + ["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; let body = "Xabcdef123456"; let body_offset = 1; - let trailer_strings = vec!["\n", "Served by Make Believe\n"]; + let trailer_strings = ["\n", "Served by Make Believe\n"]; // Write the body to a file let mut tmp = tempfile().unwrap(); @@ -114,10 +114,10 @@ fn test_sendfile_freebsd() { fn test_sendfile_dragonfly() { // Declare the content let header_strings = - vec!["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; + ["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; let body = "Xabcdef123456"; let body_offset = 1; - let trailer_strings = vec!["\n", "Served by Make Believe\n"]; + let trailer_strings = ["\n", "Served by Make Believe\n"]; // Write the body to a file let mut tmp = tempfile().unwrap(); From 4820047165f841d47b4e25a51645483c5c05c478 Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Sun, 21 May 2023 15:07:38 +0000 Subject: [PATCH 16/30] Merge #2043 2043: Clippy cleanup: r=asomers a=asomers fix the new clippy::non_minimal_cfg lint Co-authored-by: Alan Somers --- src/fcntl.rs | 4 ++-- src/sys/socket/mod.rs | 2 +- src/sys/socket/sockopt.rs | 4 ++-- test/test_fcntl.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fcntl.rs b/src/fcntl.rs index 650828345b..e227e7c0c7 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -638,7 +638,7 @@ pub fn vmsplice( } } -#[cfg(any(target_os = "linux"))] +#[cfg(target_os = "linux")] #[cfg(feature = "fs")] libc_bitflags!( /// Mode argument flags for fallocate determining operation performed on a given range. @@ -678,7 +678,7 @@ feature! { /// /// Allows the caller to directly manipulate the allocated disk space for the /// file referred to by fd. -#[cfg(any(target_os = "linux"))] +#[cfg(target_os = "linux")] #[cfg(feature = "fs")] pub fn fallocate( fd: RawFd, diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 6b6441ed88..956c8da1ff 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -229,7 +229,7 @@ pub enum SockProtocol { EthAll = (libc::ETH_P_ALL as u16).to_be() as i32, } -#[cfg(any(target_os = "linux"))] +#[cfg(target_os = "linux")] libc_bitflags! { /// Configuration flags for `SO_TIMESTAMPING` interface /// diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 06e9ee4563..2658deae74 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -678,7 +678,7 @@ sockopt_impl!( libc::IP6T_SO_ORIGINAL_DST, libc::sockaddr_in6 ); -#[cfg(any(target_os = "linux"))] +#[cfg(target_os = "linux")] sockopt_impl!( /// Specifies exact type of timestamping information collected by the kernel /// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html) @@ -697,7 +697,7 @@ sockopt_impl!( libc::SO_TIMESTAMP, bool ); -#[cfg(all(target_os = "linux"))] +#[cfg(target_os = "linux")] sockopt_impl!( /// Enable or disable the receiving of the `SO_TIMESTAMPNS` control message. ReceiveTimestampns, diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 383fde8f2d..0d285a87ad 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -238,7 +238,7 @@ mod linux_android { use nix::unistd::{close, pipe, read, write}; use tempfile::tempfile; - #[cfg(any(target_os = "linux"))] + #[cfg(target_os = "linux")] use tempfile::NamedTempFile; use crate::*; @@ -355,7 +355,7 @@ mod linux_android { close(wr).unwrap(); } - #[cfg(any(target_os = "linux"))] + #[cfg(target_os = "linux")] #[test] fn test_fallocate() { let tmp = NamedTempFile::new().unwrap(); From fa9ee6c62087889fcf2ea01d87a6762eb3f74250 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 11 Aug 2023 15:43:32 +0000 Subject: [PATCH 17/30] Merge pull request #2094 from asomers/clippy-aug-11-2023 Clippy cleanup: noop_method_call --- test/sys/test_aio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 84086f80ce..d9e2e08500 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -200,7 +200,7 @@ mod aio_read { assert_eq!(err, Ok(())); assert_eq!(aior.as_mut().aio_return().unwrap(), EXPECT.len()); } - assert_eq!(EXPECT, rbuf.deref().deref()); + assert_eq!(EXPECT, rbuf.deref()); } // Like ok, but allocates the structure on the stack. @@ -223,7 +223,7 @@ mod aio_read { assert_eq!(err, Ok(())); assert_eq!(aior.as_mut().aio_return().unwrap(), EXPECT.len()); } - assert_eq!(EXPECT, rbuf.deref().deref()); + assert_eq!(EXPECT, rbuf.deref()); } } From d9f3cb6f47bf7b678b31cabaa72dc30a103fefc5 Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 01:03:32 +0000 Subject: [PATCH 18/30] Merge #2052 2052: Fix CI with the latest rustup r=asomers a=asomers Co-authored-by: Alan Somers Co-authored-by: Ben Kimock --- .cirrus.yml | 48 +++++++++++++++++------------------------ test/sys/test_socket.rs | 6 +++--- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 4f97ec5822..a3148fdb07 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,29 +9,28 @@ env: RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings TOOL: cargo - # The MSRV - TOOLCHAIN: 1.56.1 + MSRV: 1.56.1 ZFLAGS: # Tests that don't require executing the build binaries build: &BUILD build_script: - . $HOME/.cargo/env || true - - $TOOL +$TOOLCHAIN -Vv - - rustc +$TOOLCHAIN -Vv - - $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets - - $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET - - $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- $CLIPPYFLAGS + - $TOOL -Vv + - rustc -Vv + - $TOOL $BUILD $ZFLAGS --target $TARGET --all-targets + - $TOOL doc $ZFLAGS --no-deps --target $TARGET + - $TOOL clippy $ZFLAGS --target $TARGET --all-targets -- $CLIPPYFLAGS - if [ -z "$NOHACK" ]; then mkdir -p $HOME/.cargo/bin; export PATH=$HOME/.cargo/bin:$PATH; fi - if [ -z "$NOHACK" ]; then curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-${HOST:-$TARGET}.tar.gz | tar xzf - -C ~/.cargo/bin; fi - - if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN hack $ZFLAGS check --target $TARGET --each-feature; fi + - if [ -z "$NOHACK" ]; then $TOOL hack $ZFLAGS check --target $TARGET --each-feature; fi # Tests that do require executing the binaries test: &TEST << : *BUILD test_script: - . $HOME/.cargo/env || true - - $TOOL +$TOOLCHAIN test --target $TARGET + - $TOOL test --target $TARGET # Test FreeBSD in a full VM. Test the i686 target too, in the # same VM. The binary will be built in 32-bit mode, but will execute on a @@ -53,10 +52,10 @@ task: setup_script: - kldload mqueuefs - fetch https://sh.rustup.rs -o rustup.sh - - sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN + - sh rustup.sh -y --profile=minimal --default-toolchain $MSRV - . $HOME/.cargo/env - rustup target add i686-unknown-freebsd - - rustup component add --toolchain $TOOLCHAIN clippy + - rustup component add clippy << : *TEST i386_test_script: - . $HOME/.cargo/env @@ -77,9 +76,9 @@ task: image: ghcr.io/cirruslabs/macos-ventura-base:latest setup_script: - curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs - - sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN + - sh rustup.sh -y --profile=minimal --default-toolchain $MSRV - . $HOME/.cargo/env - - rustup component add --toolchain $TOOLCHAIN clippy + - rustup component add clippy << : *TEST before_cache_script: rm -rf $CARGO_HOME/registry/index @@ -130,7 +129,7 @@ task: setup_script: - mkdir /tmp/home - curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs - - sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN + - sh rustup.sh -y --profile=minimal --default-toolchain $MSRV - . $HOME/.cargo/env - cargo install cross --version 0.2.1 # cross 0.2.2 bumped the MSRV to 1.58.1 << : *TEST @@ -167,9 +166,7 @@ task: image: rust:latest env: TARGET: x86_64-unknown-linux-gnu - TOOLCHAIN: setup_script: - - rustup target add $TARGET - rustup component add clippy << : *TEST before_cache_script: rm -rf $CARGO_HOME/registry/index @@ -244,38 +241,34 @@ task: TARGET: x86_64-unknown-netbsd setup_script: - rustup target add $TARGET - - rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET - - rustup component add --toolchain $TOOLCHAIN clippy + - rustup component add clippy << : *BUILD before_cache_script: rm -rf $CARGO_HOME/registry/index task: container: - image: rust:1.56 + # Redox's MSRV policy is unclear. Until they define it, use nightly. + image: rustlang/rust:nightly env: BUILD: check name: Redox x86_64 env: HOST: x86_64-unknown-linux-gnu TARGET: x86_64-unknown-redox - # Redox's MSRV policy is unclear. Until they define it, use nightly. - TOOLCHAIN: nightly CLIPPYFLAGS: -D warnings setup_script: - rustup target add $TARGET - - rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET - - rustup component add --toolchain $TOOLCHAIN clippy + - rustup component add clippy << : *BUILD before_cache_script: rm -rf $CARGO_HOME/registry/index -# Rust Tier 3 targets can't use Rustup +## Rust Tier 3 targets can't use Rustup task: container: image: rustlang/rust:nightly env: BUILD: check HOST: x86_64-unknown-linux-gnu - TOOLCHAIN: nightly ZFLAGS: -Zbuild-std CLIPPYFLAGS: -D warnings matrix: @@ -303,7 +296,6 @@ task: name: Minver env: HOST: x86_64-unknown-linux-gnu - TOOLCHAIN: nightly container: image: rustlang/rust:nightly setup_script: @@ -317,5 +309,5 @@ task: name: Rust Formatter container: image: rust:latest - setup_script: rustup +$TOOLCHAIN component add rustfmt - test_script: $TOOL +$TOOLCHAIN fmt --all -- --check **/*.rs + setup_script: rustup component add rustfmt + test_script: cargo fmt --all -- --check **/*.rs diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 9db5236816..2ebe4ea554 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -68,7 +68,7 @@ pub fn test_inetv4_addr_roundtrip_sockaddr_storage_to_addr() { assert_eq!(from_storage, sockaddr); } -#[cfg(any(target_os = "linux"))] +#[cfg(target_os = "linux")] #[cfg_attr(qemu, ignore)] #[test] pub fn test_timestamping() { @@ -2231,7 +2231,7 @@ pub fn test_vsock() { // Disable the test on emulated platforms because it fails in Cirrus-CI. Lack // of QEMU support is suspected. #[cfg_attr(qemu, ignore)] -#[cfg(all(target_os = "linux"))] +#[cfg(target_os = "linux")] #[test] fn test_recvmsg_timestampns() { use nix::sys::socket::*; @@ -2286,7 +2286,7 @@ fn test_recvmsg_timestampns() { // Disable the test on emulated platforms because it fails in Cirrus-CI. Lack // of QEMU support is suspected. #[cfg_attr(qemu, ignore)] -#[cfg(all(target_os = "linux"))] +#[cfg(target_os = "linux")] #[test] fn test_recvmmsg_timestampns() { use nix::sys::socket::*; From 4708cd5a73dfa44ebc5d38736bbf94306fcc7352 Mon Sep 17 00:00:00 2001 From: "bors[bot]" <26634292+bors[bot]@users.noreply.github.com> Date: Sun, 16 Apr 2023 15:36:05 +0000 Subject: [PATCH 19/30] Merge #2022 2022: Quiet Clippy::manual_slice_size_calculation lints r=asomers a=asomers Co-authored-by: Alan Somers --- src/sys/ioctl/mod.rs | 6 +++--- src/sys/ptrace/mod.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs index 98d6b5c99d..0b3fe3e769 100644 --- a/src/sys/ioctl/mod.rs +++ b/src/sys/ioctl/mod.rs @@ -712,7 +712,7 @@ macro_rules! ioctl_read_buf { pub unsafe fn $name(fd: $crate::libc::c_int, data: &mut [$ty]) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, request_code_read!($ioty, $nr, data.len() * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data)) + convert_ioctl_res!($crate::libc::ioctl(fd, request_code_read!($ioty, $nr, ::std::mem::size_of_val(data)) as $crate::sys::ioctl::ioctl_num_type, data)) } ) } @@ -751,7 +751,7 @@ macro_rules! ioctl_write_buf { pub unsafe fn $name(fd: $crate::libc::c_int, data: &[$ty]) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, data.len() * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data)) + convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, ::std::mem::size_of_val(data)) as $crate::sys::ioctl::ioctl_num_type, data)) } ) } @@ -780,7 +780,7 @@ macro_rules! ioctl_readwrite_buf { pub unsafe fn $name(fd: $crate::libc::c_int, data: &mut [$ty]) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, request_code_readwrite!($ioty, $nr, data.len() * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data)) + convert_ioctl_res!($crate::libc::ioctl(fd, request_code_readwrite!($ioty, $nr, ::std::mem::size_of_val(data)) as $crate::sys::ioctl::ioctl_num_type, data)) } ) } diff --git a/src/sys/ptrace/mod.rs b/src/sys/ptrace/mod.rs index 2b121c0b4d..88648acabc 100644 --- a/src/sys/ptrace/mod.rs +++ b/src/sys/ptrace/mod.rs @@ -1,4 +1,4 @@ -///! Provides helpers for making ptrace system calls +//! Provides helpers for making ptrace system calls #[cfg(any(target_os = "android", target_os = "linux"))] mod linux; From 94a3745d1e200497f3554c4db59fbd77c0caf8b3 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 26 Aug 2023 19:41:09 -0600 Subject: [PATCH 20/30] Fix installation of cross during CI use --locked with cargo install so it won't pull in a version of addr2line that is too new for our MSRV. --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index a3148fdb07..38b46b67aa 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -131,7 +131,7 @@ task: - curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs - sh rustup.sh -y --profile=minimal --default-toolchain $MSRV - . $HOME/.cargo/env - - cargo install cross --version 0.2.1 # cross 0.2.2 bumped the MSRV to 1.58.1 + - cargo install cross --version 0.2.1 --locked # cross 0.2.2 bumped the MSRV to 1.58.1 << : *TEST before_cache_script: rm -rf $CARGO_HOME/registry/index From 45af5387ffc5461f12eca48acf830d8d8bb43425 Mon Sep 17 00:00:00 2001 From: Stefano Garzarella Date: Tue, 13 Dec 2022 14:26:59 +0100 Subject: [PATCH 21/30] Rework vsock test We mainly provide VsockAddr, so let's try to test well that VsockAddr mapping to libc::sockaddr_vm is correct. Let's remove all interactions with the socket, since vsock may or may not be available in the environment. Testing socket(), bind(), listen(), connect(), etc. caused unexpected failures, and it's out of scope of this crate. So let's simplify the vsock test focussing on VsockAddr. This should work also on graviton, so let's try to re-enable it. Fixes #1934 Signed-off-by: Stefano Garzarella --- .cirrus.yml | 1 - test/sys/test_socket.rs | 69 +++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 38b46b67aa..b945007a3e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -142,7 +142,6 @@ task: arm_container: image: rust:1.56 env: - RUSTFLAGS: --cfg graviton -D warnings TARGET: aarch64-unknown-linux-gnu - name: Linux x86_64 container: diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 2ebe4ea554..158b745a03 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -2175,57 +2175,44 @@ pub fn test_recv_ipv6pktinfo() { } #[cfg(any(target_os = "android", target_os = "linux"))] -#[cfg_attr(graviton, ignore = "Not supported by the CI environment")] #[test] pub fn test_vsock() { - use nix::errno::Errno; - use nix::sys::socket::{ - bind, connect, listen, socket, AddressFamily, SockFlag, SockType, - VsockAddr, - }; - use nix::unistd::close; - use std::thread; + use nix::sys::socket::SockaddrLike; + use nix::sys::socket::{AddressFamily, VsockAddr}; + use std::convert::TryInto; + use std::mem; let port: u32 = 3000; - let s1 = socket( - AddressFamily::Vsock, - SockType::Stream, - SockFlag::empty(), - None, - ) - .expect("socket failed"); + let addr_local = VsockAddr::new(libc::VMADDR_CID_LOCAL, port); + assert_eq!(addr_local.cid(), libc::VMADDR_CID_LOCAL); + assert_eq!(addr_local.port(), port); - // VMADDR_CID_HYPERVISOR is reserved, so we expect an EADDRNOTAVAIL error. - let sockaddr_hv = VsockAddr::new(libc::VMADDR_CID_HYPERVISOR, port); - assert_eq!(bind(s1, &sockaddr_hv).err(), Some(Errno::EADDRNOTAVAIL)); + let addr_any = VsockAddr::new(libc::VMADDR_CID_ANY, libc::VMADDR_PORT_ANY); + assert_eq!(addr_any.cid(), libc::VMADDR_CID_ANY); + assert_eq!(addr_any.port(), libc::VMADDR_PORT_ANY); - let sockaddr_any = VsockAddr::new(libc::VMADDR_CID_ANY, port); - assert_eq!(bind(s1, &sockaddr_any), Ok(())); - listen(s1, 10).expect("listen failed"); + assert_ne!(addr_local, addr_any); + assert_ne!(calculate_hash(&addr_local), calculate_hash(&addr_any)); - let thr = thread::spawn(move || { - let cid: u32 = libc::VMADDR_CID_HOST; + let addr1 = VsockAddr::new(libc::VMADDR_CID_HOST, port); + let addr2 = VsockAddr::new(libc::VMADDR_CID_HOST, port); + assert_eq!(addr1, addr2); + assert_eq!(calculate_hash(&addr1), calculate_hash(&addr2)); - let s2 = socket( - AddressFamily::Vsock, - SockType::Stream, - SockFlag::empty(), - None, + let addr3 = unsafe { + VsockAddr::from_raw( + addr2.as_ref() as *const libc::sockaddr_vm as *const libc::sockaddr, + Some(mem::size_of::().try_into().unwrap()), ) - .expect("socket failed"); - - let sockaddr_host = VsockAddr::new(cid, port); - - // The current implementation does not support loopback devices, so, - // for now, we expect a failure on the connect. - assert_ne!(connect(s2, &sockaddr_host), Ok(())); - - close(s2).unwrap(); - }); - - close(s1).unwrap(); - thr.join().unwrap(); + } + .unwrap(); + assert_eq!( + addr3.as_ref().svm_family, + AddressFamily::Vsock as libc::sa_family_t + ); + assert_eq!(addr3.as_ref().svm_cid, addr1.cid()); + assert_eq!(addr3.as_ref().svm_port, addr1.port()); } // Disable the test on emulated platforms because it fails in Cirrus-CI. Lack From 9dc34def0596f268ae06ecf6357fe97774b3bf09 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 27 Jun 2023 17:50:31 -0600 Subject: [PATCH 22/30] Disable the doc test for sys::personality::personality on aarch64 It's failing in CI, and we don't yet know why. Possibly the cloud provider just turned on seccomp. Issue #2060 --- src/sys/personality.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sys/personality.rs b/src/sys/personality.rs index f295a05fad..30231dd7b8 100644 --- a/src/sys/personality.rs +++ b/src/sys/personality.rs @@ -80,7 +80,10 @@ pub fn get() -> Result { /// /// Example: /// -/// ``` +// Disable test on aarch64 until we know why it fails. +// https://github.com/nix-rust/nix/issues/2060 +#[cfg_attr(target_arch = "aarch64", doc = " ```no_run")] +#[cfg_attr(not(target_arch = "aarch64"), doc = " ```")] /// # use nix::sys::personality::{self, Persona}; /// let mut pers = personality::get().unwrap(); /// assert!(!pers.contains(Persona::ADDR_NO_RANDOMIZE)); From 8b66e07076e67283afb76148abf81520e241b7d1 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 6 Aug 2023 16:02:14 -0600 Subject: [PATCH 23/30] Fix Haiku build by updating tempfile to 3.7.1 https://github.com/Stebalien/tempfile/issues/246 --- Cargo.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 08c7712874..e1d8aac4d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,9 +82,7 @@ assert-impl = "0.1" lazy_static = "1.4" parking_lot = "0.12" rand = "0.8" -# tempfile 3.7.0 doesn't build on Haiku -# https://github.com/Stebalien/tempfile/issues/246 -tempfile = ">=3.3.0, < 3.7.0" +tempfile = "3.7.1" semver = "1.0.7" [target.'cfg(any(target_os = "android", target_os = "linux"))'.dev-dependencies] From 8e6d9d40af235521c92981c033a2a0d45a695b07 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 27 Aug 2023 15:47:45 -0600 Subject: [PATCH 24/30] Lock tempfile to 3.7.1 during CI on the MSRV toolchain --- .cirrus.yml | 5 + Cargo.lock.msrv | 460 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 465 insertions(+) create mode 100644 Cargo.lock.msrv diff --git a/.cirrus.yml b/.cirrus.yml index b945007a3e..5fd77fe22e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -56,6 +56,7 @@ task: - . $HOME/.cargo/env - rustup target add i686-unknown-freebsd - rustup component add clippy + - cp Cargo.lock.msrv Cargo.lock << : *TEST i386_test_script: - . $HOME/.cargo/env @@ -79,6 +80,7 @@ task: - sh rustup.sh -y --profile=minimal --default-toolchain $MSRV - . $HOME/.cargo/env - rustup component add clippy + - cp Cargo.lock.msrv Cargo.lock << : *TEST before_cache_script: rm -rf $CARGO_HOME/registry/index @@ -132,6 +134,7 @@ task: - sh rustup.sh -y --profile=minimal --default-toolchain $MSRV - . $HOME/.cargo/env - cargo install cross --version 0.2.1 --locked # cross 0.2.2 bumped the MSRV to 1.58.1 + - cp Cargo.lock.msrv Cargo.lock << : *TEST before_cache_script: rm -rf $CARGO_HOME/registry/index @@ -156,6 +159,7 @@ task: setup_script: - rustup target add $TARGET - rustup component add clippy + - cp Cargo.lock.msrv Cargo.lock << : *TEST before_cache_script: rm -rf $CARGO_HOME/registry/index @@ -241,6 +245,7 @@ task: setup_script: - rustup target add $TARGET - rustup component add clippy + - cp Cargo.lock.msrv Cargo.lock << : *BUILD before_cache_script: rm -rf $CARGO_HOME/registry/index diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv new file mode 100644 index 0000000000..285c03640f --- /dev/null +++ b/Cargo.lock.msrv @@ -0,0 +1,460 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "assert-impl" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3464313de0c867016e3e69d7e1e9ae3499bcc4c18e12283d381359ed38b5b9e" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "caps" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190baaad529bcfbde9e1a19022c42781bdb6ff9de25721abdb8fd98c0807730b" +dependencies = [ + "libc", + "thiserror", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "errno" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "fastrand" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "linux-raw-sys" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + +[[package]] +name = "nix" +version = "0.26.2" +dependencies = [ + "assert-impl", + "bitflags 2.4.0", + "caps", + "cfg-if", + "lazy_static", + "libc", + "memoffset", + "parking_lot", + "pin-utils", + "rand", + "semver", + "sysctl", + "tempfile", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "rustix" +version = "0.38.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bfe0f2582b4931a45d1fa608f8a8722e8b3c7ac54dd6d5f3b3212791fedef49" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + +[[package]] +name = "syn" +version = "2.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sysctl" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225e483f02d0ad107168dc57381a8a40c3aeea6abe47f37506931f861643cfa8" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "libc", + "thiserror", + "walkdir", +] + +[[package]] +name = "tempfile" +version = "3.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "walkdir" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" From 131e2386c0a8d569b4970f3881bed47473d9ae31 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 27 Aug 2023 17:04:41 -0600 Subject: [PATCH 25/30] Relax the tempfile requirement, and lock it to 3.6.0 during CI To fix the build on the MSRV. The build will fail if anybody tries to use 3.7.0 (with any rustc version), but 3.7.1 is ok with newer toolchains. --- Cargo.lock.msrv | 49 ++++++++++++++++++++++++++++++++++++++++--------- Cargo.toml | 2 +- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv index 285c03640f..22b209aea5 100644 --- a/Cargo.lock.msrv +++ b/Cargo.lock.msrv @@ -80,9 +80,12 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] [[package]] name = "getrandom" @@ -95,6 +98,32 @@ dependencies = [ "wasi", ] +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -109,9 +138,9 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "linux-raw-sys" -version = "0.4.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "lock_api" @@ -245,12 +274,13 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.9" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bfe0f2582b4931a45d1fa608f8a8722e8b3c7ac54dd6d5f3b3212791fedef49" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ - "bitflags 2.4.0", + "bitflags 1.3.2", "errno", + "io-lifetimes", "libc", "linux-raw-sys", "windows-sys", @@ -309,10 +339,11 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.7.1" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" +checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" dependencies = [ + "autocfg", "cfg-if", "fastrand", "redox_syscall", diff --git a/Cargo.toml b/Cargo.toml index e1d8aac4d5..e5774b004a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,7 @@ assert-impl = "0.1" lazy_static = "1.4" parking_lot = "0.12" rand = "0.8" -tempfile = "3.7.1" +tempfile = "3.3" semver = "1.0.7" [target.'cfg(any(target_os = "android", target_os = "linux"))'.dev-dependencies] From b0cf122a2ade0bacb7727e75b3b4a9b8b6da02d7 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 27 Aug 2023 17:28:15 -0600 Subject: [PATCH 26/30] release.toml: compatibility with cargo-release 0.22 (#2108) which no longer supports dev-version. [skip ci] --- release.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/release.toml b/release.toml index a47a0f8271..23488fbfa5 100644 --- a/release.toml +++ b/release.toml @@ -1,4 +1,3 @@ -dev-version = false pre-release-replacements = [ { file="CHANGELOG.md", search="Unreleased", replace="{{version}}" }, { file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}" } From 8a2325aa9570692c9122ed44c010cbebe41f81fb Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 27 Aug 2023 17:33:10 -0600 Subject: [PATCH 27/30] chore: Release nix version 0.26.3 --- CHANGELOG.md | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e3af1919..da5d9d62d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). -## [Unreleased] - ReleaseDate +## [0.26.3] - 2023-08-27 ### Fixed - Fix: send `ETH_P_ALL` in htons format diff --git a/Cargo.toml b/Cargo.toml index e5774b004a..e0e2cbe0b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "nix" description = "Rust friendly bindings to *nix APIs" edition = "2018" -version = "0.26.2" +version = "0.26.3" rust-version = "1.56" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix" From 12699b7a36c187bf8989dbe6863f200dbcff2f09 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 28 Aug 2023 09:22:18 -0600 Subject: [PATCH 28/30] Revert "Merge #2027 #2057" This reverts commit 0c3afc27d7bdbea7e5c12969e1ba0607c14b1dc9. This rolls back the version of bitflags used to 1.1. Upgrading bitflags to 2.0 inadvertently caused breaking changes in the r0.26 branch, by virtue of the methods that the bitflags! macro adds. Also, mask the bad_bit_mask lint, triggered by bitflags's generated code. That lint was the motivation for upgrading bitflags in the first place. The bitflags maintainers have decided not to fix those warnings in the 1.x release series. https://github.com/bitflags/bitflags/pull/373 Fixes #2112 --- Cargo.toml | 2 +- src/lib.rs | 1 + src/macros.rs | 2 -- src/mount/bsd.rs | 4 ++-- src/mount/linux.rs | 4 ++-- src/mqueue.rs | 2 +- src/sys/stat.rs | 4 ++-- src/sys/statvfs.rs | 1 + src/sys/termios.rs | 6 +++--- src/sys/time.rs | 2 -- src/unistd.rs | 4 ++-- 11 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0e2cbe0b4..d845521d38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ targets = [ [dependencies] libc = { version = "0.2.137", features = [ "extra_traits" ] } -bitflags = "2.3.1" +bitflags = "1.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 6b82125761..c0cfbd0110 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,6 +54,7 @@ #![warn(missing_docs)] #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(clippy::cast_ptr_alignment)] +#![allow(clippy::bad_bit_mask)] // Re-exported external crates pub use libc; diff --git a/src/macros.rs b/src/macros.rs index 2514b042c8..99e0de8866 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -63,8 +63,6 @@ macro_rules! libc_bitflags { } ) => { ::bitflags::bitflags! { - #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] - #[repr(transparent)] $(#[$outer])* pub struct $BitFlags: $T { $( diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs index 6ed2dc7fbf..771be7f436 100644 --- a/src/mount/bsd.rs +++ b/src/mount/bsd.rs @@ -392,7 +392,7 @@ impl<'a> Nmount<'a> { let niov = self.iov.len() as c_uint; let iovp = self.iov.as_mut_ptr(); - let res = unsafe { libc::nmount(iovp, niov, flags.bits()) }; + let res = unsafe { libc::nmount(iovp, niov, flags.bits) }; match Errno::result(res) { Ok(_) => Ok(()), Err(error) => { @@ -446,7 +446,7 @@ where P: ?Sized + NixPath, { let res = mountpoint.with_nix_path(|cstr| unsafe { - libc::unmount(cstr.as_ptr(), flags.bits()) + libc::unmount(cstr.as_ptr(), flags.bits) })?; Errno::result(res).map(drop) diff --git a/src/mount/linux.rs b/src/mount/linux.rs index 197854cc93..cf6a60b017 100644 --- a/src/mount/linux.rs +++ b/src/mount/linux.rs @@ -88,7 +88,7 @@ pub fn mount< s, t.as_ptr(), ty, - flags.bits(), + flags.bits, d as *const libc::c_void, ) }) @@ -108,7 +108,7 @@ pub fn umount(target: &P) -> Result<()> { pub fn umount2(target: &P, flags: MntFlags) -> Result<()> { let res = target.with_nix_path(|cstr| unsafe { - libc::umount2(cstr.as_ptr(), flags.bits()) + libc::umount2(cstr.as_ptr(), flags.bits) })?; Errno::result(res).map(drop) diff --git a/src/mqueue.rs b/src/mqueue.rs index cf8e725b3b..33599bf91d 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -139,7 +139,7 @@ impl MqAttr { /// Open a message queue /// /// See also [`mq_open(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html) -// The mode.bits() cast is only lossless on some OSes +// The mode.bits cast is only lossless on some OSes #[allow(clippy::cast_lossless)] pub fn mq_open( name: &CStr, diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 7e51c03a3f..78203bfbe3 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -177,7 +177,7 @@ pub fn mknod( dev: dev_t, ) -> Result<()> { let res = path.with_nix_path(|cstr| unsafe { - libc::mknod(cstr.as_ptr(), kind.bits() | perm.bits() as mode_t, dev) + libc::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev) })?; Errno::result(res).map(drop) @@ -202,7 +202,7 @@ pub fn mknodat( libc::mknodat( dirfd, cstr.as_ptr(), - kind.bits() | perm.bits() as mode_t, + kind.bits | perm.bits() as mode_t, dev, ) })?; diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs index 5eaa7c1aef..8de369f421 100644 --- a/src/sys/statvfs.rs +++ b/src/sys/statvfs.rs @@ -12,6 +12,7 @@ use crate::{errno::Errno, NixPath, Result}; #[cfg(not(target_os = "redox"))] libc_bitflags!( /// File system mount Flags + #[repr(C)] #[derive(Default)] pub struct FsFlags: c_ulong { /// Read Only diff --git a/src/sys/termios.rs b/src/sys/termios.rs index e59c7a363e..fba2cd8268 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -309,7 +309,7 @@ impl Termios { let termios = *self.inner.borrow_mut(); self.input_flags = InputFlags::from_bits_truncate(termios.c_iflag); self.output_flags = OutputFlags::from_bits_truncate(termios.c_oflag); - self.control_flags = ControlFlags::from_bits_retain(termios.c_cflag); + self.control_flags = ControlFlags::from_bits_truncate(termios.c_cflag); self.local_flags = LocalFlags::from_bits_truncate(termios.c_lflag); self.control_chars = termios.c_cc; #[cfg(any( @@ -355,9 +355,9 @@ libc_enum! { /// enum. /// /// B0 is special and will disable the port. - #[cfg_attr(target_os = "haiku", repr(u8))] + #[cfg_attr(all(any(target_os = "haiku"), target_pointer_width = "64"), repr(u8))] #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64"), repr(u64))] - #[cfg_attr(all(not(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64")), not(target_os = "haiku")), repr(u32))] + #[cfg_attr(not(all(any(target_os = "ios", target_os = "macos", target_os = "haiku"), target_pointer_width = "64")), repr(u32))] #[non_exhaustive] pub enum BaudRate { B0, diff --git a/src/sys/time.rs b/src/sys/time.rs index 5cabe2962a..0042c45084 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -91,7 +91,6 @@ pub(crate) mod timer { #[cfg(any(target_os = "android", target_os = "linux"))] bitflags! { /// Flags that are used for arming the timer. - #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct TimerSetTimeFlags: libc::c_int { const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME; } @@ -104,7 +103,6 @@ pub(crate) mod timer { ))] bitflags! { /// Flags that are used for arming the timer. - #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct TimerSetTimeFlags: libc::c_int { const TFD_TIMER_ABSTIME = libc::TIMER_ABSTIME; } diff --git a/src/unistd.rs b/src/unistd.rs index 14ca84369d..ca07b34a2e 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -2906,7 +2906,7 @@ feature! { pub fn access(path: &P, amode: AccessFlags) -> Result<()> { let res = path.with_nix_path(|cstr| { unsafe { - libc::access(cstr.as_ptr(), amode.bits()) + libc::access(cstr.as_ptr(), amode.bits) } })?; Errno::result(res).map(drop) @@ -2947,7 +2947,7 @@ pub fn faccessat(dirfd: Option, path: &P, mode: Acce pub fn eaccess(path: &P, mode: AccessFlags) -> Result<()> { let res = path.with_nix_path(|cstr| { unsafe { - libc::eaccess(cstr.as_ptr(), mode.bits()) + libc::eaccess(cstr.as_ptr(), mode.bits) } })?; Errno::result(res).map(drop) From eec327d5af0c05ae3fb9a49eba4ed815eae76e20 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 28 Aug 2023 14:46:01 -0600 Subject: [PATCH 29/30] Add CHANGELOG entry for PR #2117 [skip ci] --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da5d9d62d5..5573d4583e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [Unreleased] - ReleaseDate + +### Fixed + +- Fixed an unintended API change in release 0.26.3, due to the upgrade of the + bitflags dependency. + ([#2117](https://github.com/nix-rust/nix/pull/2117)) + ## [0.26.3] - 2023-08-27 ### Fixed From 08d8ba9fc3b5a0b9f6211bc286e6bf336b7c3463 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 28 Aug 2023 14:50:29 -0600 Subject: [PATCH 30/30] chore: Release nix version 0.26.4 --- CHANGELOG.md | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5573d4583e..4bc4c0c07e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). -## [Unreleased] - ReleaseDate +## [0.26.4] - 2023-08-28 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index d845521d38..ad917de06e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "nix" description = "Rust friendly bindings to *nix APIs" edition = "2018" -version = "0.26.3" +version = "0.26.4" rust-version = "1.56" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix"