Skip to content

Commit f54ad4d

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

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/sys/wait.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,52 @@ 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+
/// Note that there are two Linux-specific enum variants, `PtraceEvent`
46+
/// and `PtraceSyscall`. Portable code should avoid exhaustively
47+
/// matching on WaitStatus.
4248
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
4349
pub enum WaitStatus {
50+
/// The process exited normally (as with `exit()` or returning from
51+
/// `main`) with the given exit code. This case matches the C macro
52+
/// `WIFEXITED(status)`; the second field is `WEXITSTATUS(status)`.
4453
Exited(pid_t, i8),
54+
/// The process was killed by the given signal. The third element
55+
/// indicates whether the signal generated a core dump. This case
56+
/// matches the C macro `WIFSIGNALED(status)`; the last two fields
57+
/// correspond to `WTERMSIG(status)` and `WCOREDUMP(status)`.
4558
Signaled(pid_t, Signal, bool),
59+
/// The process is alive, but was stopped by the given signal. This
60+
/// is only reported if `WaitPidFlag::WUNTRACED` was passed. This
61+
/// case matches the C macro `WIFSTOPPED(status)`; the second field
62+
/// is `WSTOPSIG(status)`.
4663
Stopped(pid_t, Signal),
64+
/// The traced process was stopped by a `PTRACE_EVENT_*` event. See
65+
/// [nix::sys::ptrace]1 and ptrace(2) for more information. All currently
66+
/// defined events use SIGTRAP as the signal; the third field is the
67+
/// `PTRACE_EVENT_*` value of the event.
68+
///
69+
/// [nix::sys::ptrace]: ../ptrace/index.html
4770
#[cfg(any(target_os = "linux", target_os = "android"))]
4871
PtraceEvent(pid_t, Signal, c_int),
72+
/// The traced process was stopped by execution of a system call,
73+
/// and `PTRACE_O_TRACESYSGOOD` is in effect. See [nix::sys::ptrace] for
74+
/// more information.
75+
///
76+
/// [nix::sys::ptrace]: ../ptrace/index.html
4977
#[cfg(any(target_os = "linux", target_os = "android"))]
5078
PtraceSyscall(pid_t),
79+
/// The process was previously stopped but has received a SIGCONT
80+
/// signal and is now resuming execution. This is only reported if
81+
/// `WaitPidFlag::WCONTINUED` was passed. This case matches the C
82+
/// macro `WIFCONTINUED(status)`.
5183
Continued(pid_t),
84+
/// There are currently no state changes to report in any awaited
85+
/// child process. This is only returned if `WaitPidFlag::WNOHANG`
86+
/// was used (otherwise `wait()` or `waitpid()` would block until
87+
/// there was something to report).
5288
StillAlive
5389
}
5490

0 commit comments

Comments
 (0)