Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable fcntl OFD commands on macos #2300

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
contents: read

env:
MSRV: 1.69.0
MSRV: 1.71.0

jobs:

Expand Down
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
name = "nix"
description = "Rust friendly bindings to *nix APIs"
edition = "2021"
resolver = "2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version = "0.27.1"
rust-version = "1.69"
rust-version = "1.71"
authors = ["The nix-rust Project Developers"]
repository = "https:/nix-rust/nix"
license = "MIT"
Expand All @@ -28,7 +29,6 @@ targets = [
]

[dependencies]
libc = { git = "https:/rust-lang/libc", rev = "2f93bfb7678e18a9fc5373dec49384bd23f601c3", features = ["extra_traits"] }
bitflags = "2.3.1"
cfg-if = "1.0"
pin-utils = { version = "0.1.0", optional = true }
Expand Down Expand Up @@ -71,6 +71,11 @@ uio = []
user = ["feature"]
zerocopy = ["fs", "uio"]

[dependencies.libc]
git = "https:/anacrolix/rust-libc"
branch = "macos-ofd-fcntl"
features = ["extra_traits", "const-extern-fn"]

[dev-dependencies]
assert-impl = "0.1"
parking_lot = "0.12"
Expand Down
1 change: 1 addition & 0 deletions changelog/2300.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable fcntl::{F_OFD_SETLKW,F_OFD_SETLK,F_OFD_GETLK} for macOS
2 changes: 2 additions & 0 deletions changelog/2300.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use resolver "2"
Require rust version 1.71
2 changes: 2 additions & 0 deletions changelog/2300.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix libc feature deps for testing (added "const-extern-fn")
Fixed numerous clippy warnings
12 changes: 6 additions & 6 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -614,11 +614,11 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
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,
Expand Down
4 changes: 2 additions & 2 deletions src/sys/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, another type change: rust-lang/libc#3466

EPOLLIN;
EPOLLPRI;
EPOLLOUT;
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions src/sys/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> {
Expand Down Expand Up @@ -110,7 +106,7 @@ impl<'fd> FdSet<'fd> {
pub fn fds(&self, highest: Option<RawFd>) -> 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, they changed the type of this constant from usize to c_int: https:/rust-lang/libc/pull/3356/files

}
}
}
Expand Down
8 changes: 1 addition & 7 deletions test/sys/test_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions test/test_sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading