summaryrefslogtreecommitdiff
path: root/src/sys
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 /src/sys
parentff0fb3d18776151d0c8694f564ffb21164d1e17f (diff)
parentc6f9e2332efcf62c751d7a0174bb791e732b90a8 (diff)
downloadnix-3174d85d085a3d5dc64908ea12366698233645d5.zip
Merge branch 'master' into set-sockaddr-length-linux
Diffstat (limited to 'src/sys')
-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
5 files changed, 24 insertions, 11 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<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);
}