Skip to content

Commit c5529aa

Browse files
SUPERCILEXsunfishcode
authored andcommitted
Return PID from waitpid (#996)
Signed-off-by: Alex Saveau <[email protected]>
1 parent 6c5ef4f commit c5529aa

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/process/wait.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ pub enum WaitId<'a> {
310310
/// [Linux]: https://man7.org/linux/man-pages/man2/waitpid.2.html
311311
#[cfg(not(target_os = "wasi"))]
312312
#[inline]
313-
pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<WaitStatus>> {
314-
Ok(backend::process::syscalls::waitpid(pid, waitopts)?.map(|(_, status)| status))
313+
pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> {
314+
backend::process::syscalls::waitpid(pid, waitopts)
315315
}
316316

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

339339
/// `wait(waitopts)`—Wait for any of the children of calling process to

tests/process/wait.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ fn test_waitpid_none() {
1818
.expect("failed to execute child");
1919
unsafe { kill(child.id() as _, SIGSTOP) };
2020

21-
let status = process::waitpid(None, process::WaitOptions::UNTRACED)
21+
let (pid, status) = process::waitpid(None, process::WaitOptions::UNTRACED)
2222
.expect("failed to wait")
2323
.unwrap();
24+
assert_eq!(pid, process::Pid::from_child(&child));
2425
assert!(status.stopped());
2526
}
2627

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

3738
let pid = process::Pid::from_child(&child);
38-
let status = process::waitpid(Some(pid), process::WaitOptions::UNTRACED)
39+
let (rpid, status) = process::waitpid(Some(pid), process::WaitOptions::UNTRACED)
3940
.expect("failed to wait")
4041
.unwrap();
42+
assert_eq!(rpid, pid);
4143
assert!(status.stopped());
4244
}
4345

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

5456
let pgid = process::getpgrp();
55-
let status = process::waitpgid(pgid, process::WaitOptions::UNTRACED)
57+
let (pid, status) = process::waitpgid(pgid, process::WaitOptions::UNTRACED)
5658
.expect("failed to wait")
5759
.unwrap();
60+
assert_eq!(pid, process::Pid::from_child(&child));
5861
assert!(status.stopped());
5962
}
6063

0 commit comments

Comments
 (0)