summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2017-08-08 15:26:48 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2017-08-08 15:26:48 +0000
commit6334f55650845ce84623b9744aa83c5de2f98423 (patch)
treea71c109f6ace7b2b97b2ffec63a515770c7a1747 /src
parentbe7acc16247c3394cf9bc4c3bef5e91e0aa95a94 (diff)
parent0370de6cb99a320b67afebe048e9b1d9a7474b13 (diff)
downloadnix-6334f55650845ce84623b9744aa83c5de2f98423.zip
Merge #722
722: Add a convenience method .pid() for WaitStatus. r=asomers
Diffstat (limited to 'src')
-rw-r--r--src/sys/wait.rs19
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 {