unix ExitStatus: Provide .stopped_signal()

Necessary to handle WIFSTOPPED.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
This commit is contained in:
Ian Jackson 2020-12-12 21:47:47 +00:00
parent 3f05051d6b
commit f060b9e0d9
2 changed files with 15 additions and 0 deletions

View File

@ -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()
}

View File

@ -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
}