Skip to content

Commit 3174d85

Browse files
committed
Merge branch 'master' into set-sockaddr-length-linux
2 parents ff0fb3d + c6f9e23 commit 3174d85

File tree

10 files changed

+39
-23
lines changed

10 files changed

+39
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1616
- Added `mq_timedreceive` to `::nix::mqueue`.
1717
([#1966])(https://github.com/nix-rust/nix/pull/1966)
1818
- Added `LocalPeerPid` to `nix::sys::socket::sockopt` for macOS. ([#1967](https://github.com/nix-rust/nix/pull/1967))
19+
- Added `TFD_TIMER_CANCEL_ON_SET` to `::nix::sys::time::TimerSetTimeFlags` on Linux and Android.
20+
([#2040](https://github.com/nix-rust/nix/pull/2040))
1921

2022
### Changed
2123

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bitflags = "1.1"
3232
cfg-if = "1.0"
3333
pin-utils = { version = "0.1.0", optional = true }
3434
static_assertions = "1"
35-
memoffset = { version = "0.8", optional = true }
35+
memoffset = { version = "0.9", optional = true }
3636

3737
[features]
3838
default = [

src/fcntl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ pub fn vmsplice(
701701
}
702702
}
703703

704-
#[cfg(any(target_os = "linux"))]
704+
#[cfg(target_os = "linux")]
705705
#[cfg(feature = "fs")]
706706
libc_bitflags!(
707707
/// Mode argument flags for fallocate determining operation performed on a given range.
@@ -741,7 +741,7 @@ feature! {
741741
///
742742
/// Allows the caller to directly manipulate the allocated disk space for the
743743
/// file referred to by fd.
744-
#[cfg(any(target_os = "linux"))]
744+
#[cfg(target_os = "linux")]
745745
#[cfg(feature = "fs")]
746746
pub fn fallocate(
747747
fd: RawFd,

src/features.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod os {
66
use crate::sys::utsname::uname;
77
use crate::Result;
88
use std::os::unix::ffi::OsStrExt;
9+
use std::sync::atomic::{AtomicUsize, Ordering};
910

1011
// Features:
1112
// * atomic cloexec on socket: 2.6.27
@@ -72,15 +73,15 @@ mod os {
7273
}
7374

7475
fn kernel_version() -> Result<usize> {
75-
static mut KERNEL_VERS: usize = 0;
76+
static KERNEL_VERS: AtomicUsize = AtomicUsize::new(0);
77+
let mut kernel_vers = KERNEL_VERS.load(Ordering::Relaxed);
7678

77-
unsafe {
78-
if KERNEL_VERS == 0 {
79-
KERNEL_VERS = parse_kernel_version()?;
80-
}
81-
82-
Ok(KERNEL_VERS)
79+
if kernel_vers == 0 {
80+
kernel_vers = parse_kernel_version()?;
81+
KERNEL_VERS.store(kernel_vers, Ordering::Relaxed);
8382
}
83+
84+
Ok(kernel_vers)
8485
}
8586

8687
/// Check if the OS supports atomic close-on-exec for sockets

src/sys/ptrace/linux.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ unsafe fn ptrace_other(
269269
.map(|_| 0)
270270
}
271271

272-
/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
272+
/// Set options, as with `ptrace(PTRACE_SETOPTIONS, ...)`.
273273
pub fn setoptions(pid: Pid, options: Options) -> Result<()> {
274274
let res = unsafe {
275275
libc::ptrace(
@@ -282,17 +282,17 @@ pub fn setoptions(pid: Pid, options: Options) -> Result<()> {
282282
Errno::result(res).map(drop)
283283
}
284284

285-
/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)`
285+
/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG, ...)`
286286
pub fn getevent(pid: Pid) -> Result<c_long> {
287287
ptrace_get_data::<c_long>(Request::PTRACE_GETEVENTMSG, pid)
288288
}
289289

290-
/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)`
290+
/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO, ...)`
291291
pub fn getsiginfo(pid: Pid) -> Result<siginfo_t> {
292292
ptrace_get_data::<siginfo_t>(Request::PTRACE_GETSIGINFO, pid)
293293
}
294294

295-
/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO,...)`
295+
/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO, ...)`
296296
pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
297297
let ret = unsafe {
298298
Errno::clear();
@@ -517,12 +517,14 @@ pub fn sysemu_step<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
517517
}
518518
}
519519

520-
/// Reads a word from a processes memory at the given address
520+
/// Reads a word from a processes memory at the given address, as with
521+
/// ptrace(PTRACE_PEEKDATA, ...)
521522
pub fn read(pid: Pid, addr: AddressType) -> Result<c_long> {
522523
ptrace_peek(Request::PTRACE_PEEKDATA, pid, addr, ptr::null_mut())
523524
}
524525

525-
/// Writes a word into the processes memory at the given address
526+
/// Writes a word into the processes memory at the given address, as with
527+
/// ptrace(PTRACE_POKEDATA, ...)
526528
///
527529
/// # Safety
528530
///
@@ -536,13 +538,13 @@ pub unsafe fn write(
536538
ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop)
537539
}
538540

539-
/// Reads a word from a user area at `offset`.
541+
/// Reads a word from a user area at `offset`, as with ptrace(PTRACE_PEEKUSER, ...).
540542
/// The user struct definition can be found in `/usr/include/sys/user.h`.
541543
pub fn read_user(pid: Pid, offset: AddressType) -> Result<c_long> {
542544
ptrace_peek(Request::PTRACE_PEEKUSER, pid, offset, ptr::null_mut())
543545
}
544546

545-
/// Writes a word to a user area at `offset`.
547+
/// Writes a word to a user area at `offset`, as with ptrace(PTRACE_POKEUSER, ...).
546548
/// The user struct definition can be found in `/usr/include/sys/user.h`.
547549
///
548550
/// # Safety

src/sys/socket/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl SockProtocol {
236236
#[allow(non_upper_case_globals)]
237237
pub const CanBcm: SockProtocol = SockProtocol::NetlinkUserSock; // Matches libc::CAN_BCM
238238
}
239-
#[cfg(any(target_os = "linux"))]
239+
#[cfg(target_os = "linux")]
240240
libc_bitflags! {
241241
/// Configuration flags for `SO_TIMESTAMPING` interface
242242
///

src/sys/socket/sockopt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ sockopt_impl!(
683683
libc::IP6T_SO_ORIGINAL_DST,
684684
libc::sockaddr_in6
685685
);
686-
#[cfg(any(target_os = "linux"))]
686+
#[cfg(target_os = "linux")]
687687
sockopt_impl!(
688688
/// Specifies exact type of timestamping information collected by the kernel
689689
/// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
@@ -702,7 +702,7 @@ sockopt_impl!(
702702
libc::SO_TIMESTAMP,
703703
bool
704704
);
705-
#[cfg(all(target_os = "linux"))]
705+
#[cfg(target_os = "linux")]
706706
sockopt_impl!(
707707
/// Enable or disable the receiving of the `SO_TIMESTAMPNS` control message.
708708
ReceiveTimestampns,

src/sys/time.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub(crate) mod timer {
9393
/// Flags that are used for arming the timer.
9494
pub struct TimerSetTimeFlags: libc::c_int {
9595
const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME;
96+
const TFD_TIMER_CANCEL_ON_SET = libc::TFD_TIMER_CANCEL_ON_SET;
9697
}
9798
}
9899
#[cfg(any(

src/sys/timerfd.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ impl TimerFd {
135135
/// Then the one shot TimeSpec and the delay TimeSpec of the delayed
136136
/// interval are going to be interpreted as absolute.
137137
///
138+
/// # Cancel on a clock change
139+
///
140+
/// If you set a `TFD_TIMER_CANCEL_ON_SET` alongside `TFD_TIMER_ABSTIME`
141+
/// and the clock for this timer is `CLOCK_REALTIME` or `CLOCK_REALTIME_ALARM`,
142+
/// then this timer is marked as cancelable if the real-time clock undergoes
143+
/// a discontinuous change.
144+
///
138145
/// # Disabling alarms
139146
///
140147
/// Note: Only one alarm can be set for any given timer. Setting a new alarm
@@ -202,6 +209,9 @@ impl TimerFd {
202209
/// Note: If the alarm is unset, then you will wait forever.
203210
pub fn wait(&self) -> Result<()> {
204211
while let Err(e) = read(self.fd.as_fd().as_raw_fd(), &mut [0u8; 8]) {
212+
if e == Errno::ECANCELED {
213+
break;
214+
}
205215
if e != Errno::EINTR {
206216
return Err(e);
207217
}

test/test_fcntl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ mod linux_android {
238238
use nix::unistd::{close, pipe, read, write};
239239

240240
use tempfile::tempfile;
241-
#[cfg(any(target_os = "linux"))]
241+
#[cfg(target_os = "linux")]
242242
use tempfile::NamedTempFile;
243243

244244
use crate::*;
@@ -355,7 +355,7 @@ mod linux_android {
355355
close(wr).unwrap();
356356
}
357357

358-
#[cfg(any(target_os = "linux"))]
358+
#[cfg(target_os = "linux")]
359359
#[test]
360360
fn test_fallocate() {
361361
let tmp = NamedTempFile::new().unwrap();

0 commit comments

Comments
 (0)