Skip to content

Commit cf87969

Browse files
committed
Document WaitStatus and its variants
1 parent fea6ef5 commit cf87969

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/sys/wait.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,54 @@ libc_bitflags!(
3939
target_os = "android"))]
4040
const WSTOPPED: WaitPidFlag = WUNTRACED;
4141

42+
/// Possible return values from `wait()` or `waitpid()`, indicating a state
43+
/// transition in a child process. The `pid_t` member / indicates which
44+
/// process is reporting the state transition.
45+
///
46+
/// Note that there are two Linux-specific enum variants, `PtraceEvent`
47+
/// and `PtraceSyscall`. Portable code should avoid exhaustively
48+
/// matching on `WaitStatus`.
4249
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
4350
pub enum WaitStatus {
51+
/// The process exited normally (as with `exit()` or returning from
52+
/// `main`) with the given exit code. This case matches the C macro
53+
/// `WIFEXITED(status)`; the second field is `WEXITSTATUS(status)`.
4454
Exited(pid_t, i8),
55+
/// The process was killed by the given signal. The third field
56+
/// indicates whether the signal generated a core dump. This case
57+
/// matches the C macro `WIFSIGNALED(status)`; the last two fields
58+
/// correspond to `WTERMSIG(status)` and `WCOREDUMP(status)`.
4559
Signaled(pid_t, Signal, bool),
60+
/// The process is alive, but was stopped by the given signal. This
61+
/// is only reported if `WaitPidFlag::WUNTRACED` was passed. This
62+
/// case matches the C macro `WIFSTOPPED(status)`; the second field
63+
/// is `WSTOPSIG(status)`.
4664
Stopped(pid_t, Signal),
65+
/// The traced process was stopped by a `PTRACE_EVENT_*` event. See
66+
/// [`nix::sys::ptrace`] and [`ptrace`(2)] for more information. All
67+
/// currently-defined events use `SIGTRAP` as the signal; the third
68+
/// field is the `PTRACE_EVENT_*` value of the event.
69+
///
70+
/// [`nix::sys::ptrace`]: ../ptrace/index.html
71+
/// [`ptrace`(2)]: http://man7.org/linux/man-pages/man2/ptrace.2.html
4772
#[cfg(any(target_os = "linux", target_os = "android"))]
4873
PtraceEvent(pid_t, Signal, c_int),
74+
/// The traced process was stopped by execution of a system call,
75+
/// and `PTRACE_O_TRACESYSGOOD` is in effect. See [`ptrace`(2)] for
76+
/// more information.
77+
///
78+
/// [`ptrace`(2)]: http://man7.org/linux/man-pages/man2/ptrace.2.html
4979
#[cfg(any(target_os = "linux", target_os = "android"))]
5080
PtraceSyscall(pid_t),
81+
/// The process was previously stopped but has resumed execution
82+
/// after receiving a `SIGCONT` signal. This is only reported if
83+
/// `WaitPidFlag::WCONTINUED` was passed. This case matches the C
84+
/// macro `WIFCONTINUED(status)`.
5185
Continued(pid_t),
86+
/// There are currently no state changes to report in any awaited
87+
/// child process. This is only returned if `WaitPidFlag::WNOHANG`
88+
/// was used (otherwise `wait()` or `waitpid()` would block until
89+
/// there was something to report).
5290
StillAlive
5391
}
5492

test/sys/test_wait.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ fn test_wait_exit() {
2929
}
3030
}
3131

32-
#[cfg(any(target_os = "linux", target_os = "android"))]
32+
// FIXME: qemu-user only implements ptrace on x86
33+
#[cfg(all(target_os = "linux",
34+
any(target_arch = "x86", target_arch = "x86_64")))]
3335
mod ptrace {
3436
use nix::Result;
3537
use nix::sys::ptrace::*;

0 commit comments

Comments
 (0)