diff --git a/base/usr/include/string.h b/base/usr/include/string.h index 077d940c..b15e9c12 100644 --- a/base/usr/include/string.h +++ b/base/usr/include/string.h @@ -52,6 +52,9 @@ extern char * strncpy(char *dest, const char *src, size_t n); extern char * strerror(int errnum); extern size_t strxfrm(char *dest, const char *src, size_t n); +extern char * strsignal(int sign); +extern const char * const sys_siglist[]; + _End_C_Header #include diff --git a/base/usr/include/sys/signal_defs.h b/base/usr/include/sys/signal_defs.h index f43b723e..adbed753 100644 --- a/base/usr/include/sys/signal_defs.h +++ b/base/usr/include/sys/signal_defs.h @@ -37,7 +37,6 @@ #define SIGHATE 34 /* The sending process does not like you */ #define SIGWINEVENT 35 /* Window server event */ #define SIGCAT 36 /* Everybody loves cats */ - #define SIGTTOU 37 #define NUMSIGNALS 38 diff --git a/libc/string/strsignal.c b/libc/string/strsignal.c new file mode 100644 index 00000000..313f87f5 --- /dev/null +++ b/libc/string/strsignal.c @@ -0,0 +1,55 @@ +#include +#include +#include + +const char * const sys_siglist[] = { + [SIGHUP] = "Hangup", + [SIGINT] = "Interrupt", + [SIGQUIT] = "Quit", + [SIGILL] = "Illegal instruction", + [SIGTRAP] = "Trace/breakpoint trap", + [SIGABRT] = "Aborted", + [SIGEMT] = "Emulation trap", + [SIGFPE] = "Arithmetic exception", + [SIGKILL] = "Killed", + [SIGBUS] = "Bus error", + [SIGSEGV] = "Segmentation fault", + [SIGSYS] = "Bad system call", + [SIGPIPE] = "Broken pipe", + [SIGALRM] = "Alarm clock", + [SIGTERM] = "Terminated", + [SIGUSR1] = "User defined signal 1", + [SIGUSR2] = "User defined signal 2", + [SIGCHLD] = "Child process status", + [SIGPWR] = "Power failure", + [SIGWINCH] = "Window changed", + [SIGURG] = "Urgent I/O condition", + [SIGPOLL] = "Pollable event", + [SIGSTOP] = "Stopped", + [SIGTSTP] = "Stopped", + [SIGCONT] = "Continued", + [SIGTTIN] = "Stopped (tty input)", + [SIGTTOU] = "Stopped (tty output)", + [SIGTTOUT] = "Stopped (tty output)", + [SIGVTALRM] = "Virtual timer expired", + [SIGPROF] = "Profiling timer expired", + [SIGXCPU] = "CPU time limit exceeded", + [SIGXFSZ] = "File size limit exceeded", + + /* silly stuff */ + [SIGWAITING] = "Waiting", + [SIGDIAF] = "Died in a fire", + [SIGHATE] = "Hated", + [SIGWINEVENT] = "Window event", + [SIGCAT] = "Meow", +}; + +char * strsignal(int sig) { + static char _signal_description[256]; + if (sig > 0 && sig < NUMSIGNALS) { + snprintf(_signal_description, 256, "%s", sys_siglist[sig]); + } else { + snprintf(_signal_description, 256, "Killed by signal %d", sig); + } + return _signal_description; +}