@@ -695,17 +695,80 @@ impl From<c_int> for ExitStatus {
695695 }
696696}
697697
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" ,
730+ #[ cfg( target_os = "linux" ) ]
731+ libc:: SIGSTKFLT => "SIGSTKFLT" ,
732+ #[ cfg( target_os = "linux" ) ]
733+ libc:: SIGPWR => "SIGPWR" ,
734+ #[ cfg( any(
735+ target_os = "macos" ,
736+ target_os = "ios" ,
737+ target_os = "tvos" ,
738+ target_os = "freebsd" ,
739+ target_os = "netbsd" ,
740+ target_os = "openbsd" ,
741+ target_os = "dragonfly"
742+ ) ) ]
743+ libc:: SIGEMT => "SIGEMT" ,
744+ #[ cfg( any(
745+ target_os = "macos" ,
746+ target_os = "ios" ,
747+ target_os = "tvos" ,
748+ target_os = "freebsd" ,
749+ target_os = "netbsd" ,
750+ target_os = "openbsd" ,
751+ target_os = "dragonfly"
752+ ) ) ]
753+ libc:: SIGINFO => "SIGINFO" ,
754+ _ => return format ! ( "{signal}" ) ,
755+ } )
756+ . to_string ( )
757+ }
758+
698759impl fmt:: Display for ExitStatus {
699760 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
700761 if let Some ( code) = self . code ( ) {
701762 write ! ( f, "exit status: {code}" )
702763 } else if let Some ( signal) = self . signal ( ) {
764+ let signal = signal_string ( signal) ;
703765 if self . core_dumped ( ) {
704766 write ! ( f, "signal: {signal} (core dumped)" )
705767 } else {
706768 write ! ( f, "signal: {signal}" )
707769 }
708770 } else if let Some ( signal) = self . stopped_signal ( ) {
771+ let signal = signal_string ( signal) ;
709772 write ! ( f, "stopped (not terminated) by signal: {signal}" )
710773 } else if self . continued ( ) {
711774 write ! ( f, "continued (WIFCONTINUED)" )
0 commit comments