From ca3387ab148b3b0fc112515d84d1ef37325f836b Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 1 Oct 2023 17:12:23 -0600 Subject: [PATCH 1/3] Raise MSRV to 1.69.0 This allows us to use the very useful CStr::from_bytes_until_nul --- .cirrus.yml | 10 +++++----- CHANGELOG.md | 3 +++ src/mount/bsd.rs | 9 +-------- src/sys/prctl.rs | 9 +++++---- src/unistd.rs | 17 +++++++---------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 522bdafcdb..a2a7bcbfc3 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,7 +9,7 @@ env: RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings TOOL: cargo - MSRV: 1.65.0 + MSRV: 1.69.0 ZFLAGS: # Tests that don't require executing the build binaries @@ -146,7 +146,7 @@ task: matrix: - name: Linux aarch64 arm_container: - image: rust:1.65.0 + image: rust:1.69.0 cpu: 1 depends_on: - FreeBSD 14 amd64 & i686 @@ -160,13 +160,13 @@ task: TARGET: aarch64-unknown-linux-gnu - name: Linux x86_64 container: - image: rust:1.65.0 + image: rust:1.69.0 cpu: 1 env: TARGET: x86_64-unknown-linux-gnu - name: Linux x86_64 musl container: - image: rust:1.65.0 + image: rust:1.69.0 cpu: 1 depends_on: - FreeBSD 14 amd64 & i686 @@ -199,7 +199,7 @@ task: # Tasks for cross-compiling, but no testing task: container: - image: rust:1.65.0 + image: rust:1.69.0 cpu: 1 depends_on: - FreeBSD 14 amd64 & i686 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a4c441805..902d1fa5fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Changed +- The MSRV is now 1.69 + ([#2144](https://github.com/nix-rust/nix/pull/2144)) + - The following APIs now take an implementation of `AsFd` rather than a `RawFd`: diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs index 3076304cab..035c955a47 100644 --- a/src/mount/bsd.rs +++ b/src/mount/bsd.rs @@ -396,14 +396,7 @@ impl<'a> Nmount<'a> { match Errno::result(res) { Ok(_) => Ok(()), Err(error) => { - let errmsg = match errmsg.iter().position(|&x| x == 0) { - None => None, - Some(0) => None, - Some(n) => { - let sl = &errmsg[0..n + 1]; - Some(CStr::from_bytes_with_nul(sl).unwrap()) - } - }; + let errmsg = CStr::from_bytes_until_nul(&errmsg[..]).ok(); Err(NmountError::new(error, errmsg)) } } diff --git a/src/sys/prctl.rs b/src/sys/prctl.rs index 995382cb0c..715239bc83 100644 --- a/src/sys/prctl.rs +++ b/src/sys/prctl.rs @@ -151,10 +151,11 @@ pub fn get_name() -> Result { let res = unsafe { libc::prctl(libc::PR_GET_NAME, &buf, 0, 0, 0) }; - let len = buf.iter().position(|&c| c == 0).unwrap_or(buf.len()); - let name = CStr::from_bytes_with_nul(&buf[..=len]).map_err(|_| Errno::EINVAL)?; - - Errno::result(res).map(|_| name.to_owned()) + Errno::result(res).map(|_| { + CStr::from_bytes_until_nul(&buf) + .map(CStr::to_owned) + .map_err(|_| Errno::EINVAL) + }).flatten() } /// Sets the timer slack value for the calling thread. Timer slack is used by the kernel to group diff --git a/src/unistd.rs b/src/unistd.rs index 2eb23fa95c..700a4af3ba 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -28,14 +28,11 @@ use libc::{ uid_t, PATH_MAX, }; use std::convert::Infallible; -use std::ffi::{CStr, OsString}; #[cfg(not(target_os = "redox"))] -use std::ffi::{CString, OsStr}; -#[cfg(not(target_os = "redox"))] -use std::os::unix::ffi::OsStrExt; -use std::os::unix::ffi::OsStringExt; -use std::os::unix::io::RawFd; -use std::os::unix::io::{AsFd, AsRawFd, OwnedFd}; +use std::ffi::CString; +use std::ffi::{CStr, OsStr, OsString}; +use std::os::unix::ffi::{OsStrExt, OsStringExt}; +use std::os::unix::io::{AsFd, AsRawFd, OwnedFd, RawFd}; use std::path::PathBuf; use std::{fmt, mem, ptr}; @@ -3928,9 +3925,9 @@ pub fn ttyname(fd: F) -> Result { return Err(Errno::from_i32(ret)); } - let nul = buf.iter().position(|c| *c == b'\0').unwrap(); - buf.truncate(nul); - Ok(OsString::from_vec(buf).into()) + CStr::from_bytes_until_nul(&buf[..]) + .map(|s| OsStr::from_bytes(s.to_bytes()).into()) + .map_err(|_| Errno::EINVAL) } } From bc008aaee48c4e3e81a3413b892eaa6c6112f4d7 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 1 Oct 2023 19:28:39 -0600 Subject: [PATCH 2/3] Respond to review comments --- README.md | 2 +- src/mount/bsd.rs | 6 +++++- src/sys/prctl.rs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 452d65466e..157b8da120 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ The following targets are supported by `nix`: ## Minimum Supported Rust Version (MSRV) -nix is supported on Rust 1.65 and higher. Its MSRV will not be +nix is supported on Rust 1.69 and higher. Its MSRV will not be changed in the future without bumping the major or minor version. ## Contributing diff --git a/src/mount/bsd.rs b/src/mount/bsd.rs index 035c955a47..bc28b49b71 100644 --- a/src/mount/bsd.rs +++ b/src/mount/bsd.rs @@ -396,7 +396,11 @@ impl<'a> Nmount<'a> { match Errno::result(res) { Ok(_) => Ok(()), Err(error) => { - let errmsg = CStr::from_bytes_until_nul(&errmsg[..]).ok(); + let errmsg = if errmsg[0] == 0 { + None + } else { + CStr::from_bytes_until_nul(&errmsg[..]).ok() + }; Err(NmountError::new(error, errmsg)) } } diff --git a/src/sys/prctl.rs b/src/sys/prctl.rs index 715239bc83..a48065a66b 100644 --- a/src/sys/prctl.rs +++ b/src/sys/prctl.rs @@ -151,11 +151,11 @@ pub fn get_name() -> Result { let res = unsafe { libc::prctl(libc::PR_GET_NAME, &buf, 0, 0, 0) }; - Errno::result(res).map(|_| { + Errno::result(res).and_then(|_| { CStr::from_bytes_until_nul(&buf) .map(CStr::to_owned) .map_err(|_| Errno::EINVAL) - }).flatten() + }) } /// Sets the timer slack value for the calling thread. Timer slack is used by the kernel to group From ace5013b9a85a0abb58a8b1d3d71172c8512754f Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 1 Oct 2023 21:35:47 -0600 Subject: [PATCH 3/3] Switch the name of the Fuchsia CI target x86_64-fuchsia -> x86_64-unknown-fuchsia --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index a2a7bcbfc3..fc564e65aa 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -235,7 +235,7 @@ task: TARGET: arm-unknown-linux-musleabi - name: Fuchsia x86_64 env: - TARGET: x86_64-fuchsia + TARGET: x86_64-unknown-fuchsia - name: Illumos env: TARGET: x86_64-unknown-illumos