summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarred Allen <jarred@moveparallel.com>2023-05-22 14:36:59 -0700
committerJarred Allen <jarred@moveparallel.com>2023-05-22 14:36:59 -0700
commit3174d85d085a3d5dc64908ea12366698233645d5 (patch)
tree87f77bc23fc3de4b3f8fb901eaaa95657f5765e2
parentff0fb3d18776151d0c8694f564ffb21164d1e17f (diff)
parentc6f9e2332efcf62c751d7a0174bb791e732b90a8 (diff)
downloadnix-3174d85d085a3d5dc64908ea12366698233645d5.zip
Merge branch 'master' into set-sockaddr-length-linux
-rw-r--r--CHANGELOG.md2
-rw-r--r--Cargo.toml2
-rw-r--r--src/fcntl.rs4
-rw-r--r--src/features.rs15
-rw-r--r--src/sys/ptrace/linux.rs18
-rw-r--r--src/sys/socket/mod.rs2
-rw-r--r--src/sys/socket/sockopt.rs4
-rw-r--r--src/sys/time.rs1
-rw-r--r--src/sys/timerfd.rs10
-rw-r--r--test/test_fcntl.rs4
10 files changed, 39 insertions, 23 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index daa8b6d9..c87abc4b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Added `mq_timedreceive` to `::nix::mqueue`.
([#1966])(https://github.com/nix-rust/nix/pull/1966)
- Added `LocalPeerPid` to `nix::sys::socket::sockopt` for macOS. ([#1967](https://github.com/nix-rust/nix/pull/1967))
+- Added `TFD_TIMER_CANCEL_ON_SET` to `::nix::sys::time::TimerSetTimeFlags` on Linux and Android.
+ ([#2040](https://github.com/nix-rust/nix/pull/2040))
### Changed
diff --git a/Cargo.toml b/Cargo.toml
index 18b3a47d..ee3882ac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -32,7 +32,7 @@ bitflags = "1.1"
cfg-if = "1.0"
pin-utils = { version = "0.1.0", optional = true }
static_assertions = "1"
-memoffset = { version = "0.8", optional = true }
+memoffset = { version = "0.9", optional = true }
[features]
default = [
diff --git a/src/fcntl.rs b/src/fcntl.rs
index a9ef9ad1..d799ff37 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -701,7 +701,7 @@ pub fn vmsplice(
}
}
-#[cfg(any(target_os = "linux"))]
+#[cfg(target_os = "linux")]
#[cfg(feature = "fs")]
libc_bitflags!(
/// Mode argument flags for fallocate determining operation performed on a given range.
@@ -741,7 +741,7 @@ feature! {
///
/// Allows the caller to directly manipulate the allocated disk space for the
/// file referred to by fd.
-#[cfg(any(target_os = "linux"))]
+#[cfg(target_os = "linux")]
#[cfg(feature = "fs")]
pub fn fallocate(
fd: RawFd,
diff --git a/src/features.rs b/src/features.rs
index 39d17604..2f07a8fc 100644
--- a/src/features.rs
+++ b/src/features.rs
@@ -6,6 +6,7 @@ mod os {
use crate::sys::utsname::uname;
use crate::Result;
use std::os::unix::ffi::OsStrExt;
+ use std::sync::atomic::{AtomicUsize, Ordering};
// Features:
// * atomic cloexec on socket: 2.6.27
@@ -72,15 +73,15 @@ mod os {
}
fn kernel_version() -> Result<usize> {
- static mut KERNEL_VERS: usize = 0;
+ static KERNEL_VERS: AtomicUsize = AtomicUsize::new(0);
+ let mut kernel_vers = KERNEL_VERS.load(Ordering::Relaxed);
- unsafe {
- if KERNEL_VERS == 0 {
- KERNEL_VERS = parse_kernel_version()?;
- }
-
- Ok(KERNEL_VERS)
+ if kernel_vers == 0 {
+ kernel_vers = parse_kernel_version()?;
+ KERNEL_VERS.store(kernel_vers, Ordering::Relaxed);
}
+
+ Ok(kernel_vers)
}
/// Check if the OS supports atomic close-on-exec for sockets
diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs
index 9687e05d..8c134cf7 100644
--- a/src/sys/ptrace/linux.rs
+++ b/src/sys/ptrace/linux.rs
@@ -269,7 +269,7 @@ unsafe fn ptrace_other(
.map(|_| 0)
}
-/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
+/// Set options, as with `ptrace(PTRACE_SETOPTIONS, ...)`.
pub fn setoptions(pid: Pid, options: Options) -> Result<()> {
let res = unsafe {
libc::ptrace(
@@ -282,17 +282,17 @@ pub fn setoptions(pid: Pid, options: Options) -> Result<()> {
Errno::result(res).map(drop)
}
-/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)`
+/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG, ...)`
pub fn getevent(pid: Pid) -> Result<c_long> {
ptrace_get_data::<c_long>(Request::PTRACE_GETEVENTMSG, pid)
}
-/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)`
+/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO, ...)`
pub fn getsiginfo(pid: Pid) -> Result<siginfo_t> {
ptrace_get_data::<siginfo_t>(Request::PTRACE_GETSIGINFO, pid)
}
-/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO,...)`
+/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO, ...)`
pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
let ret = unsafe {
Errno::clear();
@@ -517,12 +517,14 @@ pub fn sysemu_step<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
}
}
-/// Reads a word from a processes memory at the given address
+/// Reads a word from a processes memory at the given address, as with
+/// ptrace(PTRACE_PEEKDATA, ...)
pub fn read(pid: Pid, addr: AddressType) -> Result<c_long> {
ptrace_peek(Request::PTRACE_PEEKDATA, pid, addr, ptr::null_mut())
}
-/// Writes a word into the processes memory at the given address
+/// Writes a word into the processes memory at the given address, as with
+/// ptrace(PTRACE_POKEDATA, ...)
///
/// # Safety
///
@@ -536,13 +538,13 @@ pub unsafe fn write(
ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop)
}
-/// Reads a word from a user area at `offset`.
+/// Reads a word from a user area at `offset`, as with ptrace(PTRACE_PEEKUSER, ...).
/// The user struct definition can be found in `/usr/include/sys/user.h`.
pub fn read_user(pid: Pid, offset: AddressType) -> Result<c_long> {
ptrace_peek(Request::PTRACE_PEEKUSER, pid, offset, ptr::null_mut())
}
-/// Writes a word to a user area at `offset`.
+/// Writes a word to a user area at `offset`, as with ptrace(PTRACE_POKEUSER, ...).
/// The user struct definition can be found in `/usr/include/sys/user.h`.
///
/// # Safety
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index ffab9741..c77bc961 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -236,7 +236,7 @@ impl SockProtocol {
#[allow(non_upper_case_globals)]
pub const CanBcm: SockProtocol = SockProtocol::NetlinkUserSock; // Matches libc::CAN_BCM
}
-#[cfg(any(target_os = "linux"))]
+#[cfg(target_os = "linux")]
libc_bitflags! {
/// Configuration flags for `SO_TIMESTAMPING` interface
///
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index a18b5905..d5bcda4c 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -683,7 +683,7 @@ sockopt_impl!(
libc::IP6T_SO_ORIGINAL_DST,
libc::sockaddr_in6
);
-#[cfg(any(target_os = "linux"))]
+#[cfg(target_os = "linux")]
sockopt_impl!(
/// Specifies exact type of timestamping information collected by the kernel
/// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
@@ -702,7 +702,7 @@ sockopt_impl!(
libc::SO_TIMESTAMP,
bool
);
-#[cfg(all(target_os = "linux"))]
+#[cfg(target_os = "linux")]
sockopt_impl!(
/// Enable or disable the receiving of the `SO_TIMESTAMPNS` control message.
ReceiveTimestampns,
diff --git a/src/sys/time.rs b/src/sys/time.rs
index a1894e4d..30ee5fd1 100644
--- a/src/sys/time.rs
+++ b/src/sys/time.rs
@@ -93,6 +93,7 @@ pub(crate) mod timer {
/// Flags that are used for arming the timer.
pub struct TimerSetTimeFlags: libc::c_int {
const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME;
+ const TFD_TIMER_CANCEL_ON_SET = libc::TFD_TIMER_CANCEL_ON_SET;
}
}
#[cfg(any(
diff --git a/src/sys/timerfd.rs b/src/sys/timerfd.rs
index 90a05a8c..c4337c9d 100644
--- a/src/sys/timerfd.rs
+++ b/src/sys/timerfd.rs
@@ -135,6 +135,13 @@ impl TimerFd {
/// Then the one shot TimeSpec and the delay TimeSpec of the delayed
/// interval are going to be interpreted as absolute.
///
+ /// # Cancel on a clock change
+ ///
+ /// If you set a `TFD_TIMER_CANCEL_ON_SET` alongside `TFD_TIMER_ABSTIME`
+ /// and the clock for this timer is `CLOCK_REALTIME` or `CLOCK_REALTIME_ALARM`,
+ /// then this timer is marked as cancelable if the real-time clock undergoes
+ /// a discontinuous change.
+ ///
/// # Disabling alarms
///
/// Note: Only one alarm can be set for any given timer. Setting a new alarm
@@ -202,6 +209,9 @@ impl TimerFd {
/// Note: If the alarm is unset, then you will wait forever.
pub fn wait(&self) -> Result<()> {
while let Err(e) = read(self.fd.as_fd().as_raw_fd(), &mut [0u8; 8]) {
+ if e == Errno::ECANCELED {
+ break;
+ }
if e != Errno::EINTR {
return Err(e);
}
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index 8f50f16b..de502d1a 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -238,7 +238,7 @@ mod linux_android {
use nix::unistd::{close, pipe, read, write};
use tempfile::tempfile;
- #[cfg(any(target_os = "linux"))]
+ #[cfg(target_os = "linux")]
use tempfile::NamedTempFile;
use crate::*;
@@ -355,7 +355,7 @@ mod linux_android {
close(wr).unwrap();
}
- #[cfg(any(target_os = "linux"))]
+ #[cfg(target_os = "linux")]
#[test]
fn test_fallocate() {
let tmp = NamedTempFile::new().unwrap();