Skip to content

Commit 9892c61

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

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
@@ -306,8 +306,8 @@ pub enum WaitId<'a> {
306306
/// [Linux]: https://man7.org/linux/man-pages/man2/waitpid.2.html
307307
#[cfg(not(target_os = "wasi"))]
308308
#[inline]
309-
pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<WaitStatus>> {
310-
Ok(backend::process::syscalls::waitpid(pid, waitopts)?.map(|(_, status)| status))
309+
pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> {
310+
backend::process::syscalls::waitpid(pid, waitopts)
311311
}
312312

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

335335
/// `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)