From f18ceb934038fe9139e928fd8ef3e037a61f72c1 Mon Sep 17 00:00:00 2001 From: Thomas de Queiroz Barros <38295417+thomasqueirozb@users.noreply.github.com> Date: Mon, 6 Mar 2023 00:57:19 -0300 Subject: [PATCH 01/15] Add more detail for ptrace documentation --- src/sys/ptrace/linux.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 9687e05d42..8c134cf7ee 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -269,7 +269,7 @@ unsafe fn ptrace_other( .map(|_| 0) } -/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`. +/// Set options, as with `ptrace(PTRACE_SETOPTIONS, ...)`. pub fn setoptions(pid: Pid, options: Options) -> Result<()> { let res = unsafe { libc::ptrace( @@ -282,17 +282,17 @@ pub fn setoptions(pid: Pid, options: Options) -> Result<()> { Errno::result(res).map(drop) } -/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)` +/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG, ...)` pub fn getevent(pid: Pid) -> Result { ptrace_get_data::(Request::PTRACE_GETEVENTMSG, pid) } -/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)` +/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO, ...)` pub fn getsiginfo(pid: Pid) -> Result { ptrace_get_data::(Request::PTRACE_GETSIGINFO, pid) } -/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO,...)` +/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO, ...)` pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> { let ret = unsafe { Errno::clear(); @@ -517,12 +517,14 @@ pub fn sysemu_step>>(pid: Pid, sig: T) -> Result<()> { } } -/// Reads a word from a processes memory at the given address +/// Reads a word from a processes memory at the given address, as with +/// ptrace(PTRACE_PEEKDATA, ...) pub fn read(pid: Pid, addr: AddressType) -> Result { ptrace_peek(Request::PTRACE_PEEKDATA, pid, addr, ptr::null_mut()) } -/// Writes a word into the processes memory at the given address +/// Writes a word into the processes memory at the given address, as with +/// ptrace(PTRACE_POKEDATA, ...) /// /// # Safety /// @@ -536,13 +538,13 @@ pub unsafe fn write( ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop) } -/// Reads a word from a user area at `offset`. +/// Reads a word from a user area at `offset`, as with ptrace(PTRACE_PEEKUSER, ...). /// The user struct definition can be found in `/usr/include/sys/user.h`. pub fn read_user(pid: Pid, offset: AddressType) -> Result { ptrace_peek(Request::PTRACE_PEEKUSER, pid, offset, ptr::null_mut()) } -/// Writes a word to a user area at `offset`. +/// Writes a word to a user area at `offset`, as with ptrace(PTRACE_POKEUSER, ...). /// The user struct definition can be found in `/usr/include/sys/user.h`. /// /// # Safety From 2f60820c3d11e773826705b7204216aebbad5a6c Mon Sep 17 00:00:00 2001 From: Zachary S Date: Sat, 29 Apr 2023 14:54:23 -0500 Subject: [PATCH 02/15] Remove 'static mut' usage in features::os::kernel_version. (re-commit for CI retry after rustix 0.37.18 release) --- src/features.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/features.rs b/src/features.rs index 39d17604e1..2f07a8fccd 100644 --- a/src/features.rs +++ b/src/features.rs @@ -6,6 +6,7 @@ mod os { use crate::sys::utsname::uname; use crate::Result; use std::os::unix::ffi::OsStrExt; + use std::sync::atomic::{AtomicUsize, Ordering}; // Features: // * atomic cloexec on socket: 2.6.27 @@ -72,15 +73,15 @@ mod os { } fn kernel_version() -> Result { - static mut KERNEL_VERS: usize = 0; + static KERNEL_VERS: AtomicUsize = AtomicUsize::new(0); + let mut kernel_vers = KERNEL_VERS.load(Ordering::Relaxed); - unsafe { - if KERNEL_VERS == 0 { - KERNEL_VERS = parse_kernel_version()?; - } - - Ok(KERNEL_VERS) + if kernel_vers == 0 { + kernel_vers = parse_kernel_version()?; + KERNEL_VERS.store(kernel_vers, Ordering::Relaxed); } + + Ok(kernel_vers) } /// Check if the OS supports atomic close-on-exec for sockets From a4dd9cd1165a1e5cf864c06f634b426d9c88ebc9 Mon Sep 17 00:00:00 2001 From: Andrii Pohrebniak Date: Thu, 18 May 2023 12:25:39 +0100 Subject: [PATCH 03/15] timerfd: Add TFD_TIMER_CANCEL_ON_SET flag --- CHANGELOG.md | 2 ++ src/sys/time.rs | 1 + src/sys/timerfd.rs | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index daa8b6d940..c87abc4b8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). - Added `mq_timedreceive` to `::nix::mqueue`. ([#1966])(https://github.com/nix-rust/nix/pull/1966) - Added `LocalPeerPid` to `nix::sys::socket::sockopt` for macOS. ([#1967](https://github.com/nix-rust/nix/pull/1967)) +- Added `TFD_TIMER_CANCEL_ON_SET` to `::nix::sys::time::TimerSetTimeFlags` on Linux and Android. + ([#2040](https://github.com/nix-rust/nix/pull/2040)) ### Changed diff --git a/src/sys/time.rs b/src/sys/time.rs index a1894e4d54..30ee5fd1b5 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -93,6 +93,7 @@ pub(crate) mod timer { /// Flags that are used for arming the timer. pub struct TimerSetTimeFlags: libc::c_int { const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME; + const TFD_TIMER_CANCEL_ON_SET = libc::TFD_TIMER_CANCEL_ON_SET; } } #[cfg(any( diff --git a/src/sys/timerfd.rs b/src/sys/timerfd.rs index 90a05a8ccd..c4337c9dfa 100644 --- a/src/sys/timerfd.rs +++ b/src/sys/timerfd.rs @@ -135,6 +135,13 @@ impl TimerFd { /// Then the one shot TimeSpec and the delay TimeSpec of the delayed /// interval are going to be interpreted as absolute. /// + /// # Cancel on a clock change + /// + /// If you set a `TFD_TIMER_CANCEL_ON_SET` alongside `TFD_TIMER_ABSTIME` + /// and the clock for this timer is `CLOCK_REALTIME` or `CLOCK_REALTIME_ALARM`, + /// then this timer is marked as cancelable if the real-time clock undergoes + /// a discontinuous change. + /// /// # Disabling alarms /// /// Note: Only one alarm can be set for any given timer. Setting a new alarm @@ -202,6 +209,9 @@ impl TimerFd { /// Note: If the alarm is unset, then you will wait forever. pub fn wait(&self) -> Result<()> { while let Err(e) = read(self.fd.as_fd().as_raw_fd(), &mut [0u8; 8]) { + if e == Errno::ECANCELED { + break; + } if e != Errno::EINTR { return Err(e); } From 9514900a6ae3131a2c90709dcbebbb35e512acb7 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 21 May 2023 09:35:01 +0200 Subject: [PATCH 04/15] Update memoffset to 0.9 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 18b3a47d2b..ee3882acfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ bitflags = "1.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } static_assertions = "1" -memoffset = { version = "0.8", optional = true } +memoffset = { version = "0.9", optional = true } [features] default = [ From e42c3589a3c17e69043bc76c9a087acf6e5cb83e Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 21 May 2023 08:52:42 -0600 Subject: [PATCH 05/15] Clippy cleanup: fix the new clippy::non_minimal_cfg lint --- 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 a9ef9ad1bc..d799ff378e 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -701,7 +701,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. @@ -741,7 +741,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 9b6f18efb0..1e3438eab9 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -236,7 +236,7 @@ impl SockProtocol { #[allow(non_upper_case_globals)] pub const CanBcm: SockProtocol = SockProtocol::NetlinkUserSock; // Matches libc::CAN_BCM } -#[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 a18b5905ae..d5bcda4c13 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -683,7 +683,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) @@ -702,7 +702,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 8f50f16b5a..de502d1a33 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 ee2e1deff805692c4a4cc9172b458b8a5edca44f Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 26 Apr 2023 12:13:29 +0100 Subject: [PATCH 06/15] Use .bits() method rather than field for bitflags. --- src/mount/bsd.rs | 4 ++-- src/mount/linux.rs | 4 ++-- src/mqueue.rs | 2 +- src/sys/stat.rs | 4 ++-- src/unistd.rs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) 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 5f19a5f1f7..e987603786 100644 --- a/src/mount/linux.rs +++ b/src/mount/linux.rs @@ -132,7 +132,7 @@ pub fn mount< s, t.as_ptr(), ty, - flags.bits, + flags.bits(), d as *const libc::c_void, ) }) @@ -156,7 +156,7 @@ pub fn umount(target: &P) -> Result<()> { /// See also [`umount`](https://man7.org/linux/man-pages/man2/umount.2.html) 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 ac183eb55a..7ce7d5e8bc 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 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/unistd.rs b/src/unistd.rs index 7230c3370f..afa80e9b9d 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -3375,7 +3375,7 @@ feature! { /// See [access(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html) 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) } @@ -3422,7 +3422,7 @@ pub fn faccessat( ))] 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 2e5bc8b2038b6847baad1cf11b0697b5bc67a028 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 26 Apr 2023 14:04:44 +0100 Subject: [PATCH 07/15] Update to bitflags 2.3.1. This is a new major version and requires some code changes. --- Cargo.toml | 2 +- src/macros.rs | 1 + src/sys/termios.rs | 2 +- src/sys/time.rs | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee3882acfc..243f309d58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ targets = [ [dependencies] libc = { version = "0.2.141", features = ["extra_traits"] } -bitflags = "1.1" +bitflags = "2.3.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } static_assertions = "1" diff --git a/src/macros.rs b/src/macros.rs index 5d83a5ac3c..2d3564416a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -63,6 +63,7 @@ macro_rules! libc_bitflags { } ) => { ::bitflags::bitflags! { + #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] $(#[$outer])* pub struct $BitFlags: $T { $( diff --git a/src/sys/termios.rs b/src/sys/termios.rs index b0286f51f1..0f1c995090 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( diff --git a/src/sys/time.rs b/src/sys/time.rs index 30ee5fd1b5..a0160e21ff 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; const TFD_TIMER_CANCEL_ON_SET = libc::TFD_TIMER_CANCEL_ON_SET; @@ -104,6 +105,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; } From 1a89311dd5dde148d70709ce49913a283f46b39f Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 26 Apr 2023 14:31:55 +0100 Subject: [PATCH 08/15] Use repr(transparent) for bitflags. --- src/macros.rs | 1 + src/sys/statvfs.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macros.rs b/src/macros.rs index 2d3564416a..adff2bc6be 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -64,6 +64,7 @@ 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/sys/statvfs.rs b/src/sys/statvfs.rs index c2c86624c8..35424e5e27 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 From aef996a454467f188348447707e8e7598b6c4e98 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 22 May 2023 11:23:39 +0100 Subject: [PATCH 09/15] Fix warnings. --- src/sys/event.rs | 6 +++--- test/sys/test_socket.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sys/event.rs b/src/sys/event.rs index 5dcf121ae2..ec7f7e277a 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -71,7 +71,7 @@ impl Kqueue { timeout as *const timespec } else { ptr::null() - } + }, ) }; Errno::result(res).map(|r| r as usize) @@ -86,7 +86,7 @@ impl Kqueue { 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")] @@ -171,7 +171,7 @@ libc_enum! { ))] #[doc(hidden)] pub type type_of_event_flag = u16; -#[cfg(any(target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] #[doc(hidden)] pub type type_of_event_flag = u32; libc_bitflags! { diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 0a8d0544cb..9fb7e89a57 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -10,7 +10,7 @@ use std::path::Path; use std::slice; use std::str::FromStr; -#[cfg(any(target_os = "linux"))] +#[cfg(target_os = "linux")] #[cfg_attr(qemu, ignore)] #[test] pub fn test_timestamping() { @@ -2082,7 +2082,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::*; @@ -2137,7 +2137,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 3147e67b6797ff56bee5001ce61cf508eb8129ea Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 5 Jun 2023 16:59:13 -0600 Subject: [PATCH 10/15] Update CHANGELOG for patch release 0.26.2 [skip ci] --- CHANGELOG.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c87abc4b8c..22a968dcc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,9 +36,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ([#2012](https://github.com/nix-rust/nix/pull/2012)) ### Fixed -- Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering. - ([#1964](https://github.com/nix-rust/nix/pull/1964)) -- Fix: send ETH_P_ALL in htons format +- Fix: send `ETH_P_ALL` in htons format ([#1925](https://github.com/nix-rust/nix/pull/1925)) ### Removed @@ -51,6 +49,14 @@ This project adheres to [Semantic Versioning](https://semver.org/). `nix::sys::signalfd::SignalFd` instead. ([#1938](https://github.com/nix-rust/nix/pull/1938)) +## [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)) + ## [0.26.1] - 2022-11-29 ### Fixed - Fix UB with `sys::socket::sockopt::SockType` using `SOCK_PACKET`. From 9b331316963e14c249570f5be9a65bb3269c41fd Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 5 Jun 2023 17:02:36 -0600 Subject: [PATCH 11/15] Fix CI with the latest Rustup The latest Rustup does not allow the toolchain specification to be blank, which we were using. Fix it by ensuring that only one toolchain is ever installed in a given task, so we won't need to use the +$TOOLCHAIN with cargo. --- .cirrus.yml | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 1ffe4611f4..f3624f4bde 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -8,29 +8,28 @@ env: RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings TOOL: cargo - # The MSRV - TOOLCHAIN: 1.63.0 + MSRV: 1.63.0 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 -- -D warnings + - $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 -- -D warnings - 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 @@ -52,10 +51,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 @@ -76,9 +75,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 @@ -129,7 +128,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 @@ -165,9 +164,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 @@ -242,37 +239,33 @@ 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.63.0 + # 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 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 matrix: - name: DragonFly BSD x86_64 @@ -299,7 +292,6 @@ task: name: Minver env: HOST: x86_64-unknown-linux-gnu - TOOLCHAIN: nightly container: image: rustlang/rust:nightly setup_script: @@ -313,5 +305,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 From 57cdbed0ab9077e33d48c1b7a6f44b5cc0e67cbd Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 3 Jun 2023 09:31:07 -0400 Subject: [PATCH 12/15] Clippy cleanup: fix the new clippy::non-minimal-cfg lint --- src/sys/event.rs | 4 ++-- test/sys/test_socket.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sys/event.rs b/src/sys/event.rs index 5dcf121ae2..58e48c91d9 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -86,7 +86,7 @@ impl Kqueue { 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")] @@ -171,7 +171,7 @@ libc_enum! { ))] #[doc(hidden)] pub type type_of_event_flag = u16; -#[cfg(any(target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] #[doc(hidden)] pub type type_of_event_flag = u32; libc_bitflags! { diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 0a8d0544cb..9fb7e89a57 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -10,7 +10,7 @@ use std::path::Path; use std::slice; use std::str::FromStr; -#[cfg(any(target_os = "linux"))] +#[cfg(target_os = "linux")] #[cfg_attr(qemu, ignore)] #[test] pub fn test_timestamping() { @@ -2082,7 +2082,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::*; @@ -2137,7 +2137,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 e63dd8fa5944e945557c1605b633345d07aeea27 Mon Sep 17 00:00:00 2001 From: Niels Sascha Reedijk Date: Sat, 17 Jun 2023 15:04:46 +0000 Subject: [PATCH 13/15] Haiku: `speed_t` is defined as `u8` for 32 and 64 bit systems --- src/sys/termios.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/termios.rs b/src/sys/termios.rs index b0286f51f1..694a1338d3 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -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, From fccc89f9f04a8ec6404defcd5a0882078ae75643 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 27 Jun 2023 17:50:31 -0600 Subject: [PATCH 14/15] 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 1546857f8c6a8ccd444eb656f4421003a376f5cd Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 27 Jun 2023 17:30:35 -0600 Subject: [PATCH 15/15] For invalid IP address conversions with future Rust versions 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 --- CHANGELOG.md | 5 +++++ Cargo.toml | 1 - src/sys/socket/addr.rs | 16 ++++++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c87abc4b8c..7e450900e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,11 @@ This project adheres to [Semantic Versioning](https://semver.org/). ([#1964](https://github.com/nix-rust/nix/pull/1964)) - Fix: send ETH_P_ALL in htons format ([#1925](https://github.com/nix-rust/nix/pull/1925)) +- 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)) ### Removed diff --git a/Cargo.toml b/Cargo.toml index ee3882acfc..996d1d30c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,6 @@ libc = { version = "0.2.141", features = ["extra_traits"] } bitflags = "1.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } -static_assertions = "1" memoffset = { version = "0.9", optional = true } [features] diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 4830974933..2b3a1ed439 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -39,18 +39,17 @@ 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() + } } /// These constants specify the protocol family to be used @@ -949,9 +948,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)]