Skip to content

Commit fbd575a

Browse files
committed
process::unix: Handle other wait statuses in ExitStatus as Display
Currently, on Nightly, this panics: ``` use std::process::ExitStatus; use std::os::unix::process::ExitStatusExt; fn main() { let st = ExitStatus::from_raw(0x007f); println!("st = {}", st); } ``` This is because the impl of Display assumes that if .code() is None, .signal() must be Some. That was a false assumption, although it was true with buggy code before 5b1316f unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED This is not likely to have affected many people in practice, because `Command` will never produce such a wait status (`ExitStatus`). Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
1 parent 8a9f786 commit fbd575a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,18 @@ impl fmt::Display for ExitStatus {
527527
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
528528
if let Some(code) = self.code() {
529529
write!(f, "exit code: {}", code)
530+
} else if let Some(signal) = self.signal() {
531+
if self.core_dumped() {
532+
write!(f, "signal: {} (core dumped)", signal)
533+
} else {
534+
write!(f, "signal: {}", signal)
535+
}
536+
} else if let Some(signal) = self.stopped_signal() {
537+
write!(f, "stopped (not terminated) by signal: {}", signal)
538+
} else if self.continued() {
539+
write!(f, "continued (WIFCONTINUED)")
530540
} else {
531-
let signal = self.signal().unwrap();
532-
write!(f, "signal: {}", signal)
541+
write!(f, "unrecognised wait status: {} {:#x}", self.0, self.0)
533542
}
534543
}
535544
}

0 commit comments

Comments
 (0)