diff options
author | Marcin Mielniczuk <marmistrz.dev@zoho.eu> | 2017-08-07 15:10:41 +0200 |
---|---|---|
committer | Marcin Mielniczuk <marmistrz.dev@zoho.eu> | 2017-08-08 10:05:44 +0200 |
commit | 0370de6cb99a320b67afebe048e9b1d9a7474b13 (patch) | |
tree | c1f94d4336d1f0a8d614283adcc374517785b8f4 /src | |
parent | 607ab97ac64f597e78ab321aedd3063f8e040074 (diff) | |
download | nix-0370de6cb99a320b67afebe048e9b1d9a7474b13.zip |
Add a convenience method .pid() to WaitStatus.
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/wait.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/sys/wait.rs b/src/sys/wait.rs index f31f666d..b2ca3bd6 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -93,6 +93,25 @@ pub enum WaitStatus { StillAlive } +impl WaitStatus { + /// Extracts the PID from the WaitStatus unless it equals StillAlive. + pub fn pid(&self) -> Option<Pid> { + use self::WaitStatus::*; + match *self { + Exited(p, _) => Some(p), + Signaled(p, _, _) => Some(p), + Stopped(p, _) => Some(p), + Continued(p) => Some(p), + StillAlive => None, + + #[cfg(any(target_os = "linux", target_os = "android"))] + PtraceEvent(p, _, _) => Some(p), + #[cfg(any(target_os = "linux", target_os = "android"))] + PtraceSyscall(p) => Some(p), + } + } +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod status { |