[PATCH 4/4] svstat: Show signal name as well

From: Olivier Brunel <jjk_at_jjacky.com>
Date: Sun, 18 Jan 2015 21:13:58 +0100

Signed-off-by: Olivier Brunel <jjk_at_jjacky.com>
---
 src/supervision/s6-svstat.c | 93 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 92 insertions(+), 1 deletion(-)
diff --git a/src/supervision/s6-svstat.c b/src/supervision/s6-svstat.c
index b98e69e..766d04c 100644
--- a/src/supervision/s6-svstat.c
+++ b/src/supervision/s6-svstat.c
_at_@ -68,8 +68,99 @@ int main (int argc, char const *const *argv)
       buffer_putnoflush(buffer_1small, "(", 1) ;
       if (WIFSIGNALED(status.wstat))
       {
+        struct {
+          const char *name ;
+          int num ;
+        } signals[] = {
+            { "HUP",    SIGHUP },
+            { "INT",    SIGINT },
+            { "QUIT",   SIGQUIT },
+            { "ILL",    SIGILL },
+#ifdef SIGTRAP
+            { "TRAP",   SIGTRAP },
+#endif
+            { "ABRT",   SIGABRT },
+#ifdef SIGIOT
+            { "IOT",    SIGIOT },
+#endif
+#ifdef SIGEMT
+            { "EMT",    SIGEMT },
+#endif
+#ifdef SIGBUS
+            { "BUS",    SIGBUS },
+#endif
+            { "FPE",    SIGFPE },
+            { "KILL",   SIGKILL },
+            { "USR1",   SIGUSR1 },
+            { "SEGV",   SIGSEGV },
+            { "USR2",   SIGUSR2 },
+            { "PIPE",   SIGPIPE },
+            { "ALRM",   SIGALRM },
+            { "TERM",   SIGTERM },
+#ifdef SIGSTKFLT
+            { "STKFLT", SIGSTKFLT },
+#endif
+            { "CHLD",   SIGCHLD },
+#ifdef SIGCLD
+            { "CLD",    SIGCLD },
+#endif
+            { "CONT",   SIGCONT },
+            { "STOP",   SIGSTOP },
+            { "TSTP",   SIGTSTP },
+            { "TTIN",   SIGTTIN },
+            { "TTOU",   SIGTTOU },
+#ifdef SIGURG
+            { "URG",    SIGURG },
+#endif
+#ifdef SIGXCPU
+            { "XCPU",   SIGXCPU },
+#endif
+#ifdef SIGXFSZ
+            { "XFSZ",   SIGXFSZ },
+#endif
+#ifdef SIGVTALRM
+            { "VTALRM", SIGVTALRM },
+#endif
+#ifdef SIGPROF
+            { "PROF",   SIGPROF },
+#endif
+#ifdef SIGWINCH
+            { "WINCH",  SIGWINCH },
+#endif
+#ifdef SIGIO
+            { "IO",     SIGIO },
+#endif
+#ifdef SIGPOLL
+            { "POLL",   SIGPOLL },
+#endif
+#ifdef SIGINFO
+            { "INFO",   SIGINFO },
+#endif
+#ifdef SIGLOST
+            { "LOST",   SIGLOST },
+#endif
+#ifdef SIGPWR
+            { "PWR",    SIGPWR },
+#endif
+#ifdef SIGUNUSED
+            { "UNUSED", SIGUNUSED },
+#endif
+#ifdef SIGSYS
+            { "SYS",    SIGSYS },
+#endif
+        } ;
+        int i ;
+        int l = sizeof(signals) / sizeof(signals[0]) ;
+        int sig = WTERMSIG(status.wstat) ;
+
         buffer_putnoflush(buffer_1small, "signal=", 7) ;
-        buffer_putnoflush(buffer_1small, fmt, uint_fmt(fmt, WTERMSIG(status.wstat))) ;
+        buffer_putnoflush(buffer_1small, fmt, uint_fmt(fmt, sig)) ;
+        for (i = 0; i < l; i++) if (signals[i].num == sig) break ;
+        if (i < l)
+        {
+          buffer_putnoflush(buffer_1small, ":SIG", 4) ;
+          buffer_putnoflush(buffer_1small, signals[i].name, str_len(signals[i].name)) ;
+        }
       }
       else
       {
-- 
2.2.2
Received on Sun Jan 18 2015 - 20:13:58 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC