@@ -695,18 +695,94 @@ impl From<c_int> for ExitStatus {
695
695
}
696
696
}
697
697
698
+ /// Convert a signal number to a readable, searchable name.
699
+ ///
700
+ /// This string should be displayed right after the signal number.
701
+ /// If a signal is unrecognized, it returns the empty string, so that
702
+ /// you just get the number like "0". If it is recognized, you'll get
703
+ /// something like "9 (SIGKILL)".
704
+ fn signal_string(signal: i32) -> &'static str {
705
+ match signal {
706
+ libc::SIGHUP => " (SIGHUP)",
707
+ libc::SIGINT => " (SIGINT)",
708
+ libc::SIGQUIT => " (SIGQUIT)",
709
+ libc::SIGILL => " (SIGILL)",
710
+ libc::SIGTRAP => " (SIGTRAP)",
711
+ libc::SIGABRT => " (SIGABRT)",
712
+ libc::SIGBUS => " (SIGBUS)",
713
+ libc::SIGFPE => " (SIGFPE)",
714
+ libc::SIGKILL => " (SIGKILL)",
715
+ libc::SIGUSR1 => " (SIGUSR1)",
716
+ libc::SIGSEGV => " (SIGSEGV)",
717
+ libc::SIGUSR2 => " (SIGUSR2)",
718
+ libc::SIGPIPE => " (SIGPIPE)",
719
+ libc::SIGALRM => " (SIGALRM)",
720
+ libc::SIGTERM => " (SIGTERM)",
721
+ libc::SIGCHLD => " (SIGCHLD)",
722
+ libc::SIGCONT => " (SIGCONT)",
723
+ libc::SIGSTOP => " (SIGSTOP)",
724
+ libc::SIGTSTP => " (SIGTSTP)",
725
+ libc::SIGTTIN => " (SIGTTIN)",
726
+ libc::SIGTTOU => " (SIGTTOU)",
727
+ libc::SIGURG => " (SIGURG)",
728
+ libc::SIGXCPU => " (SIGXCPU)",
729
+ libc::SIGXFSZ => " (SIGXFSZ)",
730
+ libc::SIGVTALRM => " (SIGVTALRM)",
731
+ libc::SIGPROF => " (SIGPROF)",
732
+ libc::SIGWINCH => " (SIGWINCH)",
733
+ libc::SIGIO => " (SIGIO)",
734
+ libc::SIGSYS => " (SIGSYS)",
735
+ // For information on Linux signals, run `man 7 signal`
736
+ #[cfg(all(
737
+ target_os = "linux",
738
+ any(
739
+ target_arch = "x86_64",
740
+ target_arch = "x86",
741
+ target_arch = "arm",
742
+ target_arch = "aarch64"
743
+ )
744
+ ))]
745
+ libc::SIGSTKFLT => " (SIGSTKFLT)",
746
+ #[cfg(target_os = "linux")]
747
+ libc::SIGPWR => " (SIGPWR)",
748
+ #[cfg(any(
749
+ target_os = "macos",
750
+ target_os = "ios",
751
+ target_os = "tvos",
752
+ target_os = "freebsd",
753
+ target_os = "netbsd",
754
+ target_os = "openbsd",
755
+ target_os = "dragonfly"
756
+ ))]
757
+ libc::SIGEMT => " (SIGEMT)",
758
+ #[cfg(any(
759
+ target_os = "macos",
760
+ target_os = "ios",
761
+ target_os = "tvos",
762
+ target_os = "freebsd",
763
+ target_os = "netbsd",
764
+ target_os = "openbsd",
765
+ target_os = "dragonfly"
766
+ ))]
767
+ libc::SIGINFO => " (SIGINFO)",
768
+ _ => "",
769
+ }
770
+ }
771
+
698
772
impl fmt::Display for ExitStatus {
699
773
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
700
774
if let Some(code) = self.code() {
701
775
write!(f, "exit status: {code}")
702
776
} else if let Some(signal) = self.signal() {
777
+ let signal_string = signal_string(signal);
703
778
if self.core_dumped() {
704
- write!(f, "signal: {signal} (core dumped)")
779
+ write!(f, "signal: {signal}{signal_string} (core dumped)")
705
780
} else {
706
- write!(f, "signal: {signal}")
781
+ write!(f, "signal: {signal}{signal_string} ")
707
782
}
708
783
} else if let Some(signal) = self.stopped_signal() {
709
- write!(f, "stopped (not terminated) by signal: {signal}")
784
+ let signal_string = signal_string(signal);
785
+ write!(f, "stopped (not terminated) by signal: {signal}{signal_string}")
710
786
} else if self.continued() {
711
787
write!(f, "continued (WIFCONTINUED)")
712
788
} else {
0 commit comments