From 282653726999dd948524db906ba9d28356547666 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 10:54:33 +1100 Subject: [PATCH 1/8] Enable fcntl OFD commands on macos --- src/fcntl.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fcntl.rs b/src/fcntl.rs index c1c8a4f196..392dc88ab8 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -522,15 +522,15 @@ pub enum FcntlArg<'a> { /// Get the first lock that blocks the lock description F_GETLK(&'a mut libc::flock), /// Acquire or release an open file description lock - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLK(&'a libc::flock), /// Like [`F_OFD_SETLK`](FcntlArg::F_OFD_SETLK) except that if a conflicting lock is held on /// the file, then wait for that lock to be released. - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLKW(&'a libc::flock), /// Determine whether it would be possible to create the given lock. If not, return details /// about one existing lock that would prevent it. - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_GETLK(&'a mut libc::flock), /// Add seals to the file #[cfg(any( @@ -614,11 +614,11 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result { F_SETLKW(flock) => libc::fcntl(fd, libc::F_SETLKW, flock), #[cfg(not(target_os = "redox"))] F_GETLK(flock) => libc::fcntl(fd, libc::F_GETLK, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLK(flock) => libc::fcntl(fd, libc::F_OFD_SETLK, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLKW(flock) => libc::fcntl(fd, libc::F_OFD_SETLKW, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_GETLK(flock) => libc::fcntl(fd, libc::F_OFD_GETLK, flock), #[cfg(any( linux_android, From a8e2a3364c3e4641fc9e177afd10e87aae796733 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 11:14:47 +1100 Subject: [PATCH 2/8] clippy --- src/sys/select.rs | 8 ++------ test/sys/test_select.rs | 8 +------- test/test_sendfile.rs | 4 ++-- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/sys/select.rs b/src/sys/select.rs index 64a8e258cf..6a5530fc81 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -3,7 +3,6 @@ use crate::errno::Errno; use crate::sys::time::{TimeSpec, TimeVal}; use crate::Result; use libc::{self, c_int}; -use std::convert::TryFrom; use std::iter::FusedIterator; use std::mem; use std::ops::Range; @@ -21,10 +20,7 @@ pub struct FdSet<'fd> { } fn assert_fd_valid(fd: RawFd) { - assert!( - usize::try_from(fd).map_or(false, |fd| fd < FD_SETSIZE), - "fd must be in the range 0..FD_SETSIZE", - ); + assert!(fd < FD_SETSIZE, "fd must be in the range 0..FD_SETSIZE",); } impl<'fd> FdSet<'fd> { @@ -110,7 +106,7 @@ impl<'fd> FdSet<'fd> { pub fn fds(&self, highest: Option) -> Fds { Fds { set: self, - range: 0..highest.map(|h| h as usize + 1).unwrap_or(FD_SETSIZE), + range: 0..highest.map(|h| h + 1).unwrap_or(FD_SETSIZE) as usize, } } } diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs index 746c6b6966..68e28cc149 100644 --- a/test/sys/test_select.rs +++ b/test/sys/test_select.rs @@ -68,13 +68,7 @@ macro_rules! generate_fdset_bad_fd_tests { mod test_fdset_too_large_fd { use super::*; - use std::convert::TryInto; - generate_fdset_bad_fd_tests!( - FD_SETSIZE.try_into().unwrap(), - insert, - remove, - contains, - ); + generate_fdset_bad_fd_tests!(FD_SETSIZE, insert, remove, contains,); } #[test] diff --git a/test/test_sendfile.rs b/test/test_sendfile.rs index 6333bf8662..1d6e133830 100644 --- a/test/test_sendfile.rs +++ b/test/test_sendfile.rs @@ -157,10 +157,10 @@ fn test_sendfile_dragonfly() { fn test_sendfile_darwin() { // 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 d17d271ef5fc7e95194372521c8dc79ab60e8460 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 11:15:16 +1100 Subject: [PATCH 3/8] Add missing libc feature for tests and use custom libc until merged --- Cargo.toml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 202c57b52a..4ed1454c2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "nix" description = "Rust friendly bindings to *nix APIs" edition = "2021" +resolver = "2" version = "0.27.1" rust-version = "1.69" authors = ["The nix-rust Project Developers"] @@ -28,7 +29,6 @@ targets = [ ] [dependencies] -libc = { git = "https://github.com/rust-lang/libc", rev = "2f93bfb7678e18a9fc5373dec49384bd23f601c3", features = ["extra_traits"] } bitflags = "2.3.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } @@ -71,6 +71,17 @@ uio = [] user = ["feature"] zerocopy = ["fs", "uio"] +[dependencies.libc] +git = "https://github.com/anacrolix/rust-libc" +branch = "macos-ofd-fcntl" +features = ["extra_traits"] + +[dev-dependencies.libc] +git = "https://github.com/anacrolix/rust-libc" +branch = "macos-ofd-fcntl" +# const-extern-fn is needed for tests +features = ["extra_traits", "const-extern-fn"] + [dev-dependencies] assert-impl = "0.1" parking_lot = "0.12" From 801142375a06010df35d6c731ad67ac544699b3b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 11:18:29 +1100 Subject: [PATCH 4/8] Update to rust version 1.71 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4ed1454c2c..34f904030f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "Rust friendly bindings to *nix APIs" edition = "2021" resolver = "2" version = "0.27.1" -rust-version = "1.69" +rust-version = "1.71" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix" license = "MIT" From 85a6d5f27d7a7dce3e470adb9c2d8292327f1ff7 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 11:22:00 +1100 Subject: [PATCH 5/8] Add changelog --- changelog/2300.added.md | 1 + changelog/2300.changed.md | 2 ++ changelog/2300.fixed.md | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 changelog/2300.added.md create mode 100644 changelog/2300.changed.md create mode 100644 changelog/2300.fixed.md diff --git a/changelog/2300.added.md b/changelog/2300.added.md new file mode 100644 index 0000000000..de69f67d73 --- /dev/null +++ b/changelog/2300.added.md @@ -0,0 +1 @@ +Enable fcntl::{F_OFD_SETLKW,F_OFD_SETLK,F_OFD_GETLK} for macOS diff --git a/changelog/2300.changed.md b/changelog/2300.changed.md new file mode 100644 index 0000000000..e9ea462576 --- /dev/null +++ b/changelog/2300.changed.md @@ -0,0 +1,2 @@ +Use resolver "2" +Require rust version 1.71 diff --git a/changelog/2300.fixed.md b/changelog/2300.fixed.md new file mode 100644 index 0000000000..dcd3db5cb6 --- /dev/null +++ b/changelog/2300.fixed.md @@ -0,0 +1,2 @@ +Fix libc feature deps for testing (added "const-extern-fn") +Fixed numerous clippy warnings From 8ea5ddd0eba662daa382cc5c8771250893859fd3 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 11:31:14 +1100 Subject: [PATCH 6/8] Bump MSRV in GitHub CI to 1.71 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b84767897..fa50d4f3e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ permissions: contents: read env: - MSRV: 1.69.0 + MSRV: 1.71.0 jobs: From 02b4802d4b8a8edbfa86f3dd858b04f46e322947 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 11:41:56 +1100 Subject: [PATCH 7/8] libc feature const-extern-fn is needed regardless --- Cargo.toml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34f904030f..8b7d6edf88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,12 +74,6 @@ zerocopy = ["fs", "uio"] [dependencies.libc] git = "https://github.com/anacrolix/rust-libc" branch = "macos-ofd-fcntl" -features = ["extra_traits"] - -[dev-dependencies.libc] -git = "https://github.com/anacrolix/rust-libc" -branch = "macos-ofd-fcntl" -# const-extern-fn is needed for tests features = ["extra_traits", "const-extern-fn"] [dev-dependencies] From 395b17b1aacbe8bcd7fe90a9eae7630bf6e12ff8 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Jan 2024 11:51:43 +1100 Subject: [PATCH 8/8] Update epoll flags due to libc change --- src/sys/epoll.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index ec146a8c53..e98cc5fb80 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -6,7 +6,7 @@ use std::mem; use std::os::unix::io::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd}; libc_bitflags!( - pub struct EpollFlags: c_int { + pub struct EpollFlags: u32 { EPOLLIN; EPOLLPRI; EPOLLOUT; @@ -62,7 +62,7 @@ impl EpollEvent { } pub fn events(&self) -> EpollFlags { - EpollFlags::from_bits(self.event.events as c_int).unwrap() + EpollFlags::from_bits(self.event.events as u32).unwrap() } pub fn data(&self) -> u64 {