From adadb10b1535567af141bb13aa90828d0379f541 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 5 Aug 2024 00:59:03 +0300 Subject: [PATCH] LibC: Fix strsignal() and implement psignal() --- userspace/libraries/LibC/signal.cpp | 9 +++++ userspace/libraries/LibC/string.cpp | 56 ++++++++++++++--------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/userspace/libraries/LibC/signal.cpp b/userspace/libraries/LibC/signal.cpp index 489a1606..c11c73f8 100644 --- a/userspace/libraries/LibC/signal.cpp +++ b/userspace/libraries/LibC/signal.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -10,6 +11,14 @@ int kill(pid_t pid, int sig) return syscall(SYS_KILL, pid, sig); } +void psignal(int signum, const char* message) +{ + if (message && *message) + fprintf(stderr, "%s: %s\n", message, strsignal(signum)); + else + fprintf(stderr, "%s\n", strsignal(signum)); +} + int raise(int sig) { // FIXME: won't work after multithreaded diff --git a/userspace/libraries/LibC/string.cpp b/userspace/libraries/LibC/string.cpp index 32a01d3a..3aa100e2 100644 --- a/userspace/libraries/LibC/string.cpp +++ b/userspace/libraries/LibC/string.cpp @@ -317,34 +317,34 @@ char* strsignal(int signum) static char buffer[128]; switch (signum) { - case SIGABRT: strcpy(buffer, "SIGABRT"); break; - case SIGALRM: strcpy(buffer, "SIGALRM"); break; - case SIGBUS: strcpy(buffer, "SIGBUS"); break; - case SIGCHLD: strcpy(buffer, "SIGCHLD"); break; - case SIGCONT: strcpy(buffer, "SIGCONT"); break; - case SIGFPE: strcpy(buffer, "SIGFPE"); break; - case SIGHUP: strcpy(buffer, "SIGHUP"); break; - case SIGILL: strcpy(buffer, "SIGILL"); break; - case SIGINT: strcpy(buffer, "SIGINT"); break; - case SIGKILL: strcpy(buffer, "SIGKILL"); break; - case SIGPIPE: strcpy(buffer, "SIGPIPE"); break; - case SIGQUIT: strcpy(buffer, "SIGQUIT"); break; - case SIGSEGV: strcpy(buffer, "SIGSEGV"); break; - case SIGSTOP: strcpy(buffer, "SIGSTOP"); break; - case SIGTERM: strcpy(buffer, "SIGTERM"); break; - case SIGTSTP: strcpy(buffer, "SIGTSTP"); break; - case SIGTTIN: strcpy(buffer, "SIGTTIN"); break; - case SIGTTOU: strcpy(buffer, "SIGTTOU"); break; - case SIGUSR1: strcpy(buffer, "SIGUSR1"); break; - case SIGUSR2: strcpy(buffer, "SIGUSR2"); break; - case SIGPOLL: strcpy(buffer, "SIGPOLL"); break; - case SIGPROF: strcpy(buffer, "SIGPROF"); break; - case SIGSYS: strcpy(buffer, "SIGSYS"); break; - case SIGTRAP: strcpy(buffer, "SIGTRAP"); break; - case SIGURG: strcpy(buffer, "SIGURG"); break; - case SIGVTALRM: strcpy(buffer, "SIGVTALRM"); break; - case SIGXCPU: strcpy(buffer, "SIGXCPU"); break; - case SIGXFSZ: strcpy(buffer, "SIGXFSZ"); break; + case SIGABRT: strcpy(buffer, "Process abort signal."); break; + case SIGALRM: strcpy(buffer, "Alarm clock."); break; + case SIGBUS: strcpy(buffer, "Access to an undefined portion of a memory object."); break; + case SIGCHLD: strcpy(buffer, "Child process terminated, stopped, or continued."); break; + case SIGCONT: strcpy(buffer, "Continue executing, if stopped."); break; + case SIGFPE: strcpy(buffer, "Erroneous arithmetic operation."); break; + case SIGHUP: strcpy(buffer, "Hangup."); break; + case SIGILL: strcpy(buffer, "Illegal instruction."); break; + case SIGINT: strcpy(buffer, "Terminal interrupt signal."); break; + case SIGKILL: strcpy(buffer, "Kill (cannot be caught or ignored)."); break; + case SIGPIPE: strcpy(buffer, "Write on a pipe with no one to read it."); break; + case SIGQUIT: strcpy(buffer, "Terminal quit signal."); break; + case SIGSEGV: strcpy(buffer, "Invalid memory reference."); break; + case SIGSTOP: strcpy(buffer, "Stop executing (cannot be caught or ignored)."); break; + case SIGTERM: strcpy(buffer, "Termination signal."); break; + case SIGTSTP: strcpy(buffer, "Terminal stop signal."); break; + case SIGTTIN: strcpy(buffer, "Background process attempting read."); break; + case SIGTTOU: strcpy(buffer, "Background process attempting write."); break; + case SIGUSR1: strcpy(buffer, "User-defined signal 1."); break; + case SIGUSR2: strcpy(buffer, "User-defined signal 2."); break; + case SIGPOLL: strcpy(buffer, "Pollable event."); break; + case SIGPROF: strcpy(buffer, "Profiling timer expired."); break; + case SIGSYS: strcpy(buffer, "Bad system call."); break; + case SIGTRAP: strcpy(buffer, "Trace/breakpoint trap."); break; + case SIGURG: strcpy(buffer, "High bandwidth data is available at a socket."); break; + case SIGVTALRM: strcpy(buffer, "Virtual timer expired."); break; + case SIGXCPU: strcpy(buffer, "CPU time limit exceeded."); break; + case SIGXFSZ: strcpy(buffer, "File size limit exceeded."); break; } return buffer; }