@@ -696,41 +696,46 @@ impl From<c_int> for ExitStatus {
696
696
}
697
697
698
698
/// Convert a signal number to a readable, searchable name.
699
- fn signal_string ( signal : i32 ) -> String {
700
- ( match signal {
701
- libc:: SIGHUP => "SIGHUP" ,
702
- libc:: SIGINT => "SIGINT" ,
703
- libc:: SIGQUIT => "SIGQUIT" ,
704
- libc:: SIGILL => "SIGILL" ,
705
- libc:: SIGTRAP => "SIGTRAP" ,
706
- libc:: SIGABRT => "SIGABRT" ,
707
- libc:: SIGBUS => "SIGBUS" ,
708
- libc:: SIGFPE => "SIGFPE" ,
709
- libc:: SIGKILL => "SIGKILL" ,
710
- libc:: SIGUSR1 => "SIGUSR1" ,
711
- libc:: SIGSEGV => "SIGSEGV" ,
712
- libc:: SIGUSR2 => "SIGUSR2" ,
713
- libc:: SIGPIPE => "SIGPIPE" ,
714
- libc:: SIGALRM => "SIGALRM" ,
715
- libc:: SIGTERM => "SIGTERM" ,
716
- libc:: SIGCHLD => "SIGCHLD" ,
717
- libc:: SIGCONT => "SIGCONT" ,
718
- libc:: SIGSTOP => "SIGSTOP" ,
719
- libc:: SIGTSTP => "SIGTSTP" ,
720
- libc:: SIGTTIN => "SIGTTIN" ,
721
- libc:: SIGTTOU => "SIGTTOU" ,
722
- libc:: SIGURG => "SIGURG" ,
723
- libc:: SIGXCPU => "SIGXCPU" ,
724
- libc:: SIGXFSZ => "SIGXFSZ" ,
725
- libc:: SIGVTALRM => "SIGVTALRM" ,
726
- libc:: SIGPROF => "SIGPROF" ,
727
- libc:: SIGWINCH => "SIGWINCH" ,
728
- libc:: SIGIO => "SIGIO" ,
729
- libc:: SIGSYS => "SIGSYS" ,
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)" ,
730
735
#[ cfg( target_os = "linux" ) ]
731
- libc:: SIGSTKFLT => "SIGSTKFLT" ,
736
+ libc:: SIGSTKFLT => " ( SIGSTKFLT) " ,
732
737
#[ cfg( target_os = "linux" ) ]
733
- libc:: SIGPWR => "SIGPWR" ,
738
+ libc:: SIGPWR => " ( SIGPWR) " ,
734
739
#[ cfg( any(
735
740
target_os = "macos" ,
736
741
target_os = "ios" ,
@@ -740,7 +745,7 @@ fn signal_string(signal: i32) -> String {
740
745
target_os = "openbsd" ,
741
746
target_os = "dragonfly"
742
747
) ) ]
743
- libc:: SIGEMT => "SIGEMT" ,
748
+ libc:: SIGEMT => " ( SIGEMT) " ,
744
749
#[ cfg( any(
745
750
target_os = "macos" ,
746
751
target_os = "ios" ,
@@ -750,26 +755,25 @@ fn signal_string(signal: i32) -> String {
750
755
target_os = "openbsd" ,
751
756
target_os = "dragonfly"
752
757
) ) ]
753
- libc:: SIGINFO => "SIGINFO" ,
754
- _ => return format ! ( "{signal}" ) ,
755
- } )
756
- . to_string ( )
758
+ libc:: SIGINFO => " (SIGINFO)" ,
759
+ _ => "" ,
760
+ }
757
761
}
758
762
759
763
impl fmt:: Display for ExitStatus {
760
764
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
761
765
if let Some ( code) = self . code ( ) {
762
766
write ! ( f, "exit status: {code}" )
763
767
} else if let Some ( signal) = self . signal ( ) {
764
- let signal = signal_string ( signal) ;
768
+ let signal_string = signal_string ( signal) ;
765
769
if self . core_dumped ( ) {
766
- write ! ( f, "signal: {signal} (core dumped)" )
770
+ write ! ( f, "signal: {signal}{signal_string} (core dumped)" )
767
771
} else {
768
- write ! ( f, "signal: {signal}" )
772
+ write ! ( f, "signal: {signal}{signal_string} " )
769
773
}
770
774
} else if let Some ( signal) = self . stopped_signal ( ) {
771
- let signal = signal_string ( signal) ;
772
- write ! ( f, "stopped (not terminated) by signal: {signal}" )
775
+ let signal_string = signal_string ( signal) ;
776
+ write ! ( f, "stopped (not terminated) by signal: {signal}{signal_string} " )
773
777
} else if self . continued ( ) {
774
778
write ! ( f, "continued (WIFCONTINUED)" )
775
779
} else {
0 commit comments