Skip to content

Commit 6bcae1d

Browse files
committed
feat: I/O safety for 'sys/wait'
1 parent 67f7d46 commit 6bcae1d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/sys/wait.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::convert::TryFrom;
1010
target_os = "android",
1111
all(target_os = "linux", not(target_env = "uclibc")),
1212
))]
13-
use std::os::unix::io::RawFd;
13+
use std::os::unix::io::{AsRawFd, BorrowedFd};
1414

1515
libc_bitflags!(
1616
/// Controls the behavior of [`waitpid`].
@@ -343,8 +343,8 @@ pub fn wait() -> Result<WaitStatus> {
343343
target_os = "haiku",
344344
all(target_os = "linux", not(target_env = "uclibc")),
345345
))]
346-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
347-
pub enum Id {
346+
#[derive(Debug)]
347+
pub enum Id<'fd> {
348348
/// Wait for any child
349349
All,
350350
/// Wait for the child whose process ID matches the given PID
@@ -355,7 +355,7 @@ pub enum Id {
355355
PGid(Pid),
356356
/// Wait for the child referred to by the given PID file descriptor
357357
#[cfg(any(target_os = "android", target_os = "linux"))]
358-
PIDFd(RawFd),
358+
PIDFd(BorrowedFd<'fd>),
359359
}
360360

361361
/// Wait for a process to change status
@@ -373,7 +373,7 @@ pub fn waitid(id: Id, flags: WaitPidFlag) -> Result<WaitStatus> {
373373
Id::Pid(pid) => (libc::P_PID, pid.as_raw() as libc::id_t),
374374
Id::PGid(pid) => (libc::P_PGID, pid.as_raw() as libc::id_t),
375375
#[cfg(any(target_os = "android", target_os = "linux"))]
376-
Id::PIDFd(fd) => (libc::P_PIDFD, fd as libc::id_t),
376+
Id::PIDFd(fd) => (libc::P_PIDFD, fd.as_raw_fd() as libc::id_t),
377377
};
378378

379379
let siginfo = unsafe {

0 commit comments

Comments
 (0)