From f18ceb934038fe9139e928fd8ef3e037a61f72c1 Mon Sep 17 00:00:00 2001 From: Thomas de Queiroz Barros <38295417+thomasqueirozb@users.noreply.github.com> Date: Mon, 6 Mar 2023 00:57:19 -0300 Subject: Add more detail for ptrace documentation --- src/sys/ptrace/linux.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 { ptrace_get_data::(Request::PTRACE_GETEVENTMSG, pid) } -/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)` +/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO, ...)` pub fn getsiginfo(pid: Pid) -> Result { ptrace_get_data::(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>>(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 { 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 { 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 -- cgit v1.2.3 From 2f60820c3d11e773826705b7204216aebbad5a6c Mon Sep 17 00:00:00 2001 From: Zachary S Date: Sat, 29 Apr 2023 14:54:23 -0500 Subject: Remove 'static mut' usage in features::os::kernel_version. (re-commit for CI retry after rustix 0.37.18 release) --- src/features.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 { - 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 -- cgit v1.2.3 From a4dd9cd1165a1e5cf864c06f634b426d9c88ebc9 Mon Sep 17 00:00:00 2001 From: Andrii Pohrebniak Date: Thu, 18 May 2023 12:25:39 +0100 Subject: timerfd: Add TFD_TIMER_CANCEL_ON_SET flag --- CHANGELOG.md | 2 ++ src/sys/time.rs | 1 + src/sys/timerfd.rs | 10 ++++++++++ 3 files changed, 13 insertions(+) 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/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); } -- cgit v1.2.3 From 9514900a6ae3131a2c90709dcbebbb35e512acb7 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 21 May 2023 09:35:01 +0200 Subject: Update memoffset to 0.9 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = [ -- cgit v1.2.3 From e42c3589a3c17e69043bc76c9a087acf6e5cb83e Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 21 May 2023 08:52:42 -0600 Subject: Clippy cleanup: fix the new clippy::non_minimal_cfg lint --- src/fcntl.rs | 4 ++-- src/sys/socket/mod.rs | 2 +- src/sys/socket/sockopt.rs | 4 ++-- test/test_fcntl.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) 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/sys/socket/mod.rs b/src/sys/socket/mod.rs index 9b6f18ef..1e3438ea 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/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(); -- cgit v1.2.3