about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2020-12-12 21:47:47 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2021-01-13 12:50:29 +0000
commitf060b9e0d9277ae522a34ca06312c5857c9aadb0 (patch)
treedb00d03802f37437f69cbf7125b2ff578e594f48 /library/std/src/sys
parent3f05051d6bcb7b8562577324d59a2435a40992e9 (diff)
downloadrust-f060b9e0d9277ae522a34ca06312c5857c9aadb0.tar.gz
rust-f060b9e0d9277ae522a34ca06312c5857c9aadb0.zip
unix ExitStatus: Provide .stopped_signal()
Necessary to handle WIFSTOPPED.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/ext/process.rs11
-rw-r--r--library/std/src/sys/unix/process/process_unix.rs4
2 files changed, 15 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/ext/process.rs b/library/std/src/sys/unix/ext/process.rs
index 827cc0b9828..5efe08340f4 100644
--- a/library/std/src/sys/unix/ext/process.rs
+++ b/library/std/src/sys/unix/ext/process.rs
@@ -180,6 +180,13 @@ pub trait ExitStatusExt {
     #[unstable(feature = "unix_process_wait_more", issue = "none")]
     fn core_dumped(&self) -> bool;
 
+    /// If the process was stopped by a signal, returns that signal.
+    ///
+    /// Ie, if `WIFSTOPPED`, this returns `WSTOPSIG`.  This is only possible if the status came from
+    /// a `wait` system call which was passed `WUNTRACED`, was then converted into an `ExitStatus`.
+    #[unstable(feature = "unix_process_wait_more", issue = "none")]
+    fn stopped_signal(&self) -> Option<i32>;
+
     /// Returns the underlying raw `wait` status.
     #[unstable(feature = "unix_process_wait_more", issue = "none")]
     fn into_raw(self) -> i32;
@@ -199,6 +206,10 @@ impl ExitStatusExt for process::ExitStatus {
         self.as_inner().core_dumped()
     }
 
+    fn stopped_signal(&self) -> Option<i32> {
+        self.as_inner().stopped_signal()
+    }
+
     fn into_raw(self) -> i32 {
         self.as_inner().into_raw().into()
     }
diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs
index 99b1011578a..069a1145f76 100644
--- a/library/std/src/sys/unix/process/process_unix.rs
+++ b/library/std/src/sys/unix/process/process_unix.rs
@@ -486,6 +486,10 @@ impl ExitStatus {
         libc::WIFSIGNALED(self.0) && libc::WCOREDUMP(self.0)
     }
 
+    pub fn stopped_signal(&self) -> Option<i32> {
+        if libc::WIFSTOPPED(self.0) { Some(libc::WSTOPSIG(self.0)) } else { None }
+    }
+
     pub fn into_raw(&self) -> c_int {
         self.0
     }