Skip to content

Commit

Permalink
Return PID from waitpid (#996)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored Jan 20, 2024
1 parent 7e520b8 commit 1efd93c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/process/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ pub enum WaitId<'a> {
/// [Linux]: https://man7.org/linux/man-pages/man2/waitpid.2.html
#[cfg(not(target_os = "wasi"))]
#[inline]
pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<WaitStatus>> {
Ok(backend::process::syscalls::waitpid(pid, waitopts)?.map(|(_, status)| status))
pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> {
backend::process::syscalls::waitpid(pid, waitopts)
}

/// `waitpid(-pgid, waitopts)`—Wait for a process in a specific process group
Expand All @@ -328,8 +328,8 @@ pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<Wai
/// [Linux]: https://man7.org/linux/man-pages/man2/waitpid.2.html
#[cfg(not(target_os = "wasi"))]
#[inline]
pub fn waitpgid(pgid: Pid, waitopts: WaitOptions) -> io::Result<Option<WaitStatus>> {
Ok(backend::process::syscalls::waitpgid(pgid, waitopts)?.map(|(_, status)| status))
pub fn waitpgid(pgid: Pid, waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> {
backend::process::syscalls::waitpgid(pgid, waitopts)
}

/// `wait(waitopts)`—Wait for any of the children of calling process to
Expand Down
9 changes: 6 additions & 3 deletions tests/process/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ fn test_waitpid_none() {
.expect("failed to execute child");
unsafe { kill(child.id() as _, SIGSTOP) };

let status = process::waitpid(None, process::WaitOptions::UNTRACED)
let (pid, status) = process::waitpid(None, process::WaitOptions::UNTRACED)
.expect("failed to wait")
.unwrap();
assert_eq!(pid, process::Pid::from_child(&child));
assert!(status.stopped());
}

Expand All @@ -35,9 +36,10 @@ fn test_waitpid_some() {
unsafe { kill(child.id() as _, SIGSTOP) };

let pid = process::Pid::from_child(&child);
let status = process::waitpid(Some(pid), process::WaitOptions::UNTRACED)
let (rpid, status) = process::waitpid(Some(pid), process::WaitOptions::UNTRACED)
.expect("failed to wait")
.unwrap();
assert_eq!(rpid, pid);
assert!(status.stopped());
}

Expand All @@ -52,9 +54,10 @@ fn test_waitpgid() {
unsafe { kill(child.id() as _, SIGSTOP) };

let pgid = process::getpgrp();
let status = process::waitpgid(pgid, process::WaitOptions::UNTRACED)
let (pid, status) = process::waitpgid(pgid, process::WaitOptions::UNTRACED)
.expect("failed to wait")
.unwrap();
assert_eq!(pid, process::Pid::from_child(&child));
assert!(status.stopped());
}

Expand Down

0 comments on commit 1efd93c

Please sign in to comment.