Skip to content

Commit a72936d

Browse files
asomersSteveLauC
andauthored
Address multiple CI failures (#2642)
* Fix the test_fcntl::test_posix_fallocate::success test with recent ZFS POSIX 1003.1-2024 Issue 8 changed the error code for this operation, and recent ZFS versions have followed suit. So the test should accept either the old error code (EINVAL) or the new one (ENOTSUP). https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_fallocate.html * Clippy cleanup: mismatched_lifetime_syntaxes * fixup to Clippy cleanup: mismatched_lifetime_syntaxes * Remove the `PartialEq` and `Eq` implementations from `SigHandler` Because it never worked reliably anyway. See https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html for more info. Alternatively, we could only remove `Eq` and leave `PartialEq`. We would be able to guarantee equality or inequality in most cases, but would be unable to prove that different handler functions are actually different. I think users would find that confusing. Reported by: Clippy (unpredictable_function_pointer_comparisons) * Fix rustdoc::redundant_explicit_links warning on nightly * Clippy::doc_overindented_list_items Fix the lint in one file, but suppress it in src/sys/aio.rs, where the docstrings are nicely formated for reading in either plain text or html. * fixup to Clippy cleanup: mismatched_lifetime_syntaxes * fixup to Fix rustdoc::redundant_explicit_links warning on nightly * clippy fix: mismatched-lifetime-syntaxes * chore: pin libc to 0.2.172 to avoid the broken timespec --------- Co-authored-by: Steve Lau <[email protected]>
1 parent befe95e commit a72936d

File tree

16 files changed

+51
-48
lines changed

16 files changed

+51
-48
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ targets = [
2828
]
2929

3030
[dependencies]
31-
libc = { version = "0.2.171", features = ["extra_traits"] }
31+
libc = { version = "=0.2.172", features = ["extra_traits"] }
3232
bitflags = "2.3.3"
3333
cfg-if = "1.0"
3434
pin-utils = { version = "0.1.0", optional = true }

changelog/2642.removed.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Removed `Eq` and `PartialEq` implementations from `SigHandler`, because they
2+
never worked reliably. The suggested alternative is `matches!`. For example:
3+
```
4+
let h: SigHandler = ...
5+
if matches!(h, SigHandler::SigIgn) {
6+
...
7+
}
8+
```

src/dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Dir {
119119
}
120120

121121
/// Returns an iterator of `Result<Entry>` which rewinds when finished.
122-
pub fn iter(&mut self) -> Iter {
122+
pub fn iter(&mut self) -> Iter<'_> {
123123
Iter(self)
124124
}
125125
}
@@ -133,7 +133,7 @@ impl Dir {
133133
unsafe impl Send for Dir {}
134134

135135
impl std::os::fd::AsFd for Dir {
136-
fn as_fd(&self) -> std::os::fd::BorrowedFd {
136+
fn as_fd(&self) -> std::os::fd::BorrowedFd<'_> {
137137
let raw_fd = self.as_raw_fd();
138138

139139
// SAFETY:

src/fcntl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,15 +745,15 @@ pub enum FcntlArg<'a> {
745745
F_SETFL(OFlag), // O_NONBLOCK
746746
/// Set or clear a file segment lock
747747
F_SETLK(&'a libc::flock),
748-
/// Like [`F_SETLK`](FcntlArg::F_SETLK) except that if a shared or exclusive lock is blocked by
748+
/// Like [`F_SETLK`] except that if a shared or exclusive lock is blocked by
749749
/// other locks, the process waits until the request can be satisfied.
750750
F_SETLKW(&'a libc::flock),
751751
/// Get the first lock that blocks the lock description
752752
F_GETLK(&'a mut libc::flock),
753753
/// Acquire or release an open file description lock
754754
#[cfg(linux_android)]
755755
F_OFD_SETLK(&'a libc::flock),
756-
/// Like [`F_OFD_SETLK`](FcntlArg::F_OFD_SETLK) except that if a conflicting lock is held on
756+
/// Like [`F_OFD_SETLK`] except that if a conflicting lock is held on
757757
/// the file, then wait for that lock to be released.
758758
#[cfg(linux_android)]
759759
F_OFD_SETLKW(&'a libc::flock),

src/mqueue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub fn mq_remove_nonblock(mqd: &MqdT) -> Result<MqAttr> {
315315
#[cfg(any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly"))]
316316
impl AsFd for MqdT {
317317
/// Borrow the underlying message queue descriptor.
318-
fn as_fd(&self) -> BorrowedFd {
318+
fn as_fd(&self) -> BorrowedFd<'_> {
319319
// SAFETY: [MqdT] will only contain a valid fd by construction.
320320
unsafe { BorrowedFd::borrow_raw(self.0) }
321321
}

src/sys/aio.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//! [`cancel`](trait.Aio.html#method.cancel) or
2424
//! [`aio_cancel_all`](fn.aio_cancel_all.html), though the operating system may
2525
//! not support this for all filesystems and devices.
26+
#![allow(clippy::doc_overindented_list_items)] // It looks better this way
2627
#[cfg(target_os = "freebsd")]
2728
use std::io::{IoSlice, IoSliceMut};
2829
use std::{
@@ -313,7 +314,7 @@ pub trait Aio {
313314
fn error(self: Pin<&mut Self>) -> Result<()>;
314315

315316
/// Returns the underlying file descriptor associated with the operation.
316-
fn fd(&self) -> BorrowedFd;
317+
fn fd(&self) -> BorrowedFd<'_>;
317318

318319
/// Does this operation currently have any in-kernel state?
319320
///
@@ -572,8 +573,9 @@ impl<'a> AioRead<'a> {
572573
/// * `fd`: File descriptor to read from
573574
/// * `offs`: File offset
574575
/// * `buf`: A memory buffer. It must outlive the `AioRead`.
575-
/// * `prio`: If POSIX Prioritized IO is supported, then the operation
576-
/// will be prioritized at the process's priority level minus `prio`
576+
/// * `prio`: If POSIX Prioritized IO is supported, then the
577+
/// operation will be prioritized at the process's
578+
/// priority level minus `prio`.
577579
/// * `sigev_notify`: Determines how you will be notified of event completion.
578580
pub fn new(
579581
fd: BorrowedFd<'a>,
@@ -802,8 +804,9 @@ impl<'a> AioWrite<'a> {
802804
/// * `fd`: File descriptor to write to
803805
/// * `offs`: File offset
804806
/// * `buf`: A memory buffer. It must outlive the `AioWrite`.
805-
/// * `prio`: If POSIX Prioritized IO is supported, then the operation
806-
/// will be prioritized at the process's priority level minus `prio`
807+
/// * `prio`: If POSIX Prioritized IO is supported, then the
808+
/// operation will be prioritized at the process's
809+
/// priority level minus `prio`
807810
/// * `sigev_notify`: Determines how you will be notified of event completion.
808811
pub fn new(
809812
fd: BorrowedFd<'a>,

src/sys/eventfd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl EventFd {
101101
}
102102
}
103103
impl AsFd for EventFd {
104-
fn as_fd(&self) -> BorrowedFd {
104+
fn as_fd(&self) -> BorrowedFd<'_> {
105105
self.0.as_fd()
106106
}
107107
}

src/sys/fanotify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl FanotifyEvent {
229229
/// The file descriptor of the event. If the value is `None` when reading
230230
/// from the fanotify group, this event is to notify that a group queue
231231
/// overflow occured.
232-
pub fn fd(&self) -> Option<BorrowedFd> {
232+
pub fn fd(&self) -> Option<BorrowedFd<'_>> {
233233
if self.0.fd == libc::FAN_NOFD {
234234
None
235235
} else {
@@ -443,4 +443,4 @@ impl Fanotify {
443443
fd
444444
}
445445
}
446-
}
446+
}

src/sys/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'fd> FdSet<'fd> {
107107
/// assert_eq!(fds, vec![4, 9]);
108108
/// ```
109109
#[inline]
110-
pub fn fds(&self, highest: Option<RawFd>) -> Fds {
110+
pub fn fds(&self, highest: Option<RawFd>) -> Fds<'_, '_> {
111111
Fds {
112112
set: self,
113113
range: 0..highest.map(|h| h as usize + 1).unwrap_or(FD_SETSIZE),

src/sys/signal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'a> IntoIterator for &'a SigSet {
753753
}
754754

755755
/// A signal handler.
756-
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
756+
#[derive(Clone, Copy, Debug, Hash)]
757757
pub enum SigHandler {
758758
/// Default signal handling.
759759
SigDfl,
@@ -1035,7 +1035,7 @@ pub fn sigprocmask(how: SigmaskHow, set: Option<&SigSet>, oldset: Option<&mut Si
10351035
/// - If less than `-1`, the signal is sent to all processes whose
10361036
/// process group ID is equal to the absolute value of `pid`.
10371037
/// * `signal` - Signal to send. If `None`, error checking is performed
1038-
/// but no signal is actually sent.
1038+
/// but no signal is actually sent.
10391039
///
10401040
/// See Also
10411041
/// [`kill(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html)

src/sys/signalfd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl SignalFd {
146146
}
147147

148148
impl AsFd for SignalFd {
149-
fn as_fd(&self) -> BorrowedFd {
149+
fn as_fd(&self) -> BorrowedFd<'_> {
150150
self.0.as_fd()
151151
}
152152
}

src/sys/socket/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ impl<S> RecvMsg<'_, '_, S> {
701701
/// Iterate over the valid control messages pointed to by this msghdr. If
702702
/// allocated space for CMSGs was too small it is not safe to iterate,
703703
/// instead return an `Error::ENOBUFS` error.
704-
pub fn cmsgs(&self) -> Result<CmsgIterator> {
704+
pub fn cmsgs(&self) -> Result<CmsgIterator<'_>> {
705705

706706
if self.mhdr.msg_flags & MSG_CTRUNC == MSG_CTRUNC {
707707
return Err(Errno::ENOBUFS);

src/sys/socket/sockopt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ pub struct SetOsString<'a> {
19551955

19561956
#[cfg(any(target_os = "freebsd", linux_android, target_os = "illumos"))]
19571957
impl<'a> Set<'a, OsString> for SetOsString<'a> {
1958-
fn new(val: &OsString) -> SetOsString {
1958+
fn new(val: &OsString) -> SetOsString<'_> {
19591959
SetOsString {
19601960
val: val.as_os_str(),
19611961
}

src/sys/termios.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl Termios {
178178
///
179179
/// This is not part of `nix`'s public API because it requires additional work to maintain type
180180
/// safety.
181-
pub(crate) fn get_libc_termios(&self) -> Ref<libc::termios> {
181+
pub(crate) fn get_libc_termios(&self) -> Ref<'_, libc::termios> {
182182
{
183183
let mut termios = self.inner.borrow_mut();
184184
termios.c_iflag = self.input_flags.bits();

test/sys/test_signal.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,23 @@ fn test_signal() {
112112

113113
unsafe { signal(Signal::SIGINT, SigHandler::SigIgn) }.unwrap();
114114
raise(Signal::SIGINT).unwrap();
115-
assert_eq!(
116-
unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap(),
117-
SigHandler::SigIgn
118-
);
115+
let h = unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap();
116+
assert!(matches!(h, SigHandler::SigIgn));
119117

120118
let handler = SigHandler::Handler(test_sigaction_handler);
121-
assert_eq!(
122-
unsafe { signal(Signal::SIGINT, handler) }.unwrap(),
123-
SigHandler::SigDfl
124-
);
119+
let h = unsafe { signal(Signal::SIGINT, handler) }.unwrap();
120+
assert!(matches!(h, SigHandler::SigDfl));
125121
raise(Signal::SIGINT).unwrap();
126122
assert!(SIGNALED.load(Ordering::Relaxed));
127123

124+
let h = unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap();
128125
#[cfg(not(solarish))]
129-
assert_eq!(
130-
unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap(),
131-
handler
132-
);
126+
assert!(matches!(h, SigHandler::Handler(_)));
133127

134128
// System V based OSes (e.g. illumos and Solaris) always resets the
135129
// disposition to SIG_DFL prior to calling the signal handler
136130
#[cfg(solarish)]
137-
assert_eq!(
138-
unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap(),
139-
SigHandler::SigDfl
140-
);
131+
assert!(matches!(h, SigHandler::SigDfl));
141132

142133
// Restore default signal handler
143134
unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap();
@@ -307,21 +298,21 @@ fn test_sigaction() {
307298
action_sig.flags(),
308299
SaFlags::SA_ONSTACK | SaFlags::SA_RESTART
309300
);
310-
assert_eq!(action_sig.handler(), handler_sig);
301+
assert!(matches!(action_sig.handler(), SigHandler::Handler(_)));
311302

312303
mask = action_sig.mask();
313304
assert!(mask.contains(SIGUSR1));
314305
assert!(!mask.contains(SIGUSR2));
315306

316307
let handler_act = SigHandler::SigAction(test_sigaction_action);
317308
let action_act = SigAction::new(handler_act, flags, mask);
318-
assert_eq!(action_act.handler(), handler_act);
309+
assert!(matches!(action_act.handler(), SigHandler::SigAction(_)));
319310

320311
let action_dfl = SigAction::new(SigHandler::SigDfl, flags, mask);
321-
assert_eq!(action_dfl.handler(), SigHandler::SigDfl);
312+
assert!(matches!(action_dfl.handler(), SigHandler::SigDfl));
322313

323314
let action_ign = SigAction::new(SigHandler::SigIgn, flags, mask);
324-
assert_eq!(action_ign.handler(), SigHandler::SigIgn);
315+
assert!(matches!(action_ign.handler(), SigHandler::SigIgn));
325316
})
326317
.join()
327318
.unwrap();

test/test_fcntl.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,14 @@ mod test_posix_fallocate {
541541
assert_eq!(tmp.read(&mut data).expect("read failure"), LEN);
542542
assert_eq!(&data[..], &[0u8; LEN][..]);
543543
}
544-
Err(Errno::EINVAL) => {
545-
// POSIX requires posix_fallocate to return EINVAL both for
546-
// invalid arguments (i.e. len < 0) and if the operation is not
547-
// supported by the file system.
548-
// There's no way to tell for sure whether the file system
549-
// supports posix_fallocate, so we must pass the test if it
550-
// returns EINVAL.
544+
Err(Errno::ENOTSUP) | Err(Errno::EINVAL) => {
545+
// POSIX 1003.1-2024 Issue 8 specified ENOTSUP for "the file
546+
// system does not support this operation", so Nix should accept
547+
// that error code and pass the test.
548+
// But older POSIX required posix_fallocate to return EINVAL
549+
// both for invalid arguments (i.e. len < 0) and if the
550+
// operation is not supported by the file system. So we must
551+
// also pass the test if it returns EINVAL.
551552
}
552553
_ => res.unwrap(),
553554
}

0 commit comments

Comments
 (0)