diff options
Diffstat (limited to 'library/std/src/sys/unix/process/process_unix.rs')
| -rw-r--r-- | library/std/src/sys/unix/process/process_unix.rs | 90 |
1 files changed, 47 insertions, 43 deletions
diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 188e356a8b4..31f1ea76701 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -696,41 +696,46 @@ impl From<c_int> for ExitStatus { } /// Convert a signal number to a readable, searchable name. -fn signal_string(signal: i32) -> String { - (match signal { - libc::SIGHUP => "SIGHUP", - libc::SIGINT => "SIGINT", - libc::SIGQUIT => "SIGQUIT", - libc::SIGILL => "SIGILL", - libc::SIGTRAP => "SIGTRAP", - libc::SIGABRT => "SIGABRT", - libc::SIGBUS => "SIGBUS", - libc::SIGFPE => "SIGFPE", - libc::SIGKILL => "SIGKILL", - libc::SIGUSR1 => "SIGUSR1", - libc::SIGSEGV => "SIGSEGV", - libc::SIGUSR2 => "SIGUSR2", - libc::SIGPIPE => "SIGPIPE", - libc::SIGALRM => "SIGALRM", - libc::SIGTERM => "SIGTERM", - libc::SIGCHLD => "SIGCHLD", - libc::SIGCONT => "SIGCONT", - libc::SIGSTOP => "SIGSTOP", - libc::SIGTSTP => "SIGTSTP", - libc::SIGTTIN => "SIGTTIN", - libc::SIGTTOU => "SIGTTOU", - libc::SIGURG => "SIGURG", - libc::SIGXCPU => "SIGXCPU", - libc::SIGXFSZ => "SIGXFSZ", - libc::SIGVTALRM => "SIGVTALRM", - libc::SIGPROF => "SIGPROF", - libc::SIGWINCH => "SIGWINCH", - libc::SIGIO => "SIGIO", - libc::SIGSYS => "SIGSYS", +/// +/// This string should be displayed right after the signal number. +/// If a signal is unrecognized, it returns the empty string, so that +/// you just get the number like "0". If it is recognized, you'll get +/// something like "9 (SIGKILL)". +fn signal_string(signal: i32) -> &'static str { + match signal { + libc::SIGHUP => " (SIGHUP)", + libc::SIGINT => " (SIGINT)", + libc::SIGQUIT => " (SIGQUIT)", + libc::SIGILL => " (SIGILL)", + libc::SIGTRAP => " (SIGTRAP)", + libc::SIGABRT => " (SIGABRT)", + libc::SIGBUS => " (SIGBUS)", + libc::SIGFPE => " (SIGFPE)", + libc::SIGKILL => " (SIGKILL)", + libc::SIGUSR1 => " (SIGUSR1)", + libc::SIGSEGV => " (SIGSEGV)", + libc::SIGUSR2 => " (SIGUSR2)", + libc::SIGPIPE => " (SIGPIPE)", + libc::SIGALRM => " (SIGALRM)", + libc::SIGTERM => " (SIGTERM)", + libc::SIGCHLD => " (SIGCHLD)", + libc::SIGCONT => " (SIGCONT)", + libc::SIGSTOP => " (SIGSTOP)", + libc::SIGTSTP => " (SIGTSTP)", + libc::SIGTTIN => " (SIGTTIN)", + libc::SIGTTOU => " (SIGTTOU)", + libc::SIGURG => " (SIGURG)", + libc::SIGXCPU => " (SIGXCPU)", + libc::SIGXFSZ => " (SIGXFSZ)", + libc::SIGVTALRM => " (SIGVTALRM)", + libc::SIGPROF => " (SIGPROF)", + libc::SIGWINCH => " (SIGWINCH)", + libc::SIGIO => " (SIGIO)", + libc::SIGSYS => " (SIGSYS)", #[cfg(target_os = "linux")] - libc::SIGSTKFLT => "SIGSTKFLT", + libc::SIGSTKFLT => " (SIGSTKFLT)", #[cfg(target_os = "linux")] - libc::SIGPWR => "SIGPWR", + libc::SIGPWR => " (SIGPWR)", #[cfg(any( target_os = "macos", target_os = "ios", @@ -740,7 +745,7 @@ fn signal_string(signal: i32) -> String { target_os = "openbsd", target_os = "dragonfly" ))] - libc::SIGEMT => "SIGEMT", + libc::SIGEMT => " (SIGEMT)", #[cfg(any( target_os = "macos", target_os = "ios", @@ -750,10 +755,9 @@ fn signal_string(signal: i32) -> String { target_os = "openbsd", target_os = "dragonfly" ))] - libc::SIGINFO => "SIGINFO", - _ => return format!("{signal}"), - }) - .to_string() + libc::SIGINFO => " (SIGINFO)", + _ => "", + } } impl fmt::Display for ExitStatus { @@ -761,15 +765,15 @@ impl fmt::Display for ExitStatus { if let Some(code) = self.code() { write!(f, "exit status: {code}") } else if let Some(signal) = self.signal() { - let signal = signal_string(signal); + let signal_string = signal_string(signal); if self.core_dumped() { - write!(f, "signal: {signal} (core dumped)") + write!(f, "signal: {signal}{signal_string} (core dumped)") } else { - write!(f, "signal: {signal}") + write!(f, "signal: {signal}{signal_string}") } } else if let Some(signal) = self.stopped_signal() { - let signal = signal_string(signal); - write!(f, "stopped (not terminated) by signal: {signal}") + let signal_string = signal_string(signal); + write!(f, "stopped (not terminated) by signal: {signal}{signal_string}") } else if self.continued() { write!(f, "continued (WIFCONTINUED)") } else { |
