Skip to content

Commit f060b9e

Browse files
committed
unix ExitStatus: Provide .stopped_signal()
Necessary to handle WIFSTOPPED. Signed-off-by: Ian Jackson <[email protected]>
1 parent 3f05051 commit f060b9e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

library/std/src/sys/unix/ext/process.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ pub trait ExitStatusExt {
180180
#[unstable(feature = "unix_process_wait_more", issue = "none")]
181181
fn core_dumped(&self) -> bool;
182182

183+
/// If the process was stopped by a signal, returns that signal.
184+
///
185+
/// Ie, if `WIFSTOPPED`, this returns `WSTOPSIG`. This is only possible if the status came from
186+
/// a `wait` system call which was passed `WUNTRACED`, was then converted into an `ExitStatus`.
187+
#[unstable(feature = "unix_process_wait_more", issue = "none")]
188+
fn stopped_signal(&self) -> Option<i32>;
189+
183190
/// Returns the underlying raw `wait` status.
184191
#[unstable(feature = "unix_process_wait_more", issue = "none")]
185192
fn into_raw(self) -> i32;
@@ -199,6 +206,10 @@ impl ExitStatusExt for process::ExitStatus {
199206
self.as_inner().core_dumped()
200207
}
201208

209+
fn stopped_signal(&self) -> Option<i32> {
210+
self.as_inner().stopped_signal()
211+
}
212+
202213
fn into_raw(self) -> i32 {
203214
self.as_inner().into_raw().into()
204215
}

library/std/src/sys/unix/process/process_unix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ impl ExitStatus {
486486
libc::WIFSIGNALED(self.0) && libc::WCOREDUMP(self.0)
487487
}
488488

489+
pub fn stopped_signal(&self) -> Option<i32> {
490+
if libc::WIFSTOPPED(self.0) { Some(libc::WSTOPSIG(self.0)) } else { None }
491+
}
492+
489493
pub fn into_raw(&self) -> c_int {
490494
self.0
491495
}

0 commit comments

Comments
 (0)