From d407b6791316c3288a5b5f8373a609c26a6c9dc0 Mon Sep 17 00:00:00 2001 From: tmatis Date: Sun, 5 Nov 2023 20:41:03 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20signal=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libft/srcs/string/ft_signalname.c | 5 ++++- srcs/signals/signals_handle.c | 9 ++++++--- srcs/syscall/param_log/log_sigset_struct.c | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libft/srcs/string/ft_signalname.c b/libft/srcs/string/ft_signalname.c index a49c1e8..caddd48 100644 --- a/libft/srcs/string/ft_signalname.c +++ b/libft/srcs/string/ft_signalname.c @@ -1,6 +1,7 @@ #include #include #include +#include #define SIGNAL_NAME(signalname) [signalname] = #signalname @@ -50,5 +51,7 @@ const char *ft_signalname(int sig) for (int i = 0; i < (int)ELEM_COUNT(signals); i++) if (i == sig) return signals[i]; - return "UNKNOWN"; + static char buf[32]; + ft_snprintf(buf, sizeof(buf), "SIGRT_%d", sig - ELEM_COUNT(signals)); + return buf; } \ No newline at end of file diff --git a/srcs/signals/signals_handle.c b/srcs/signals/signals_handle.c index 9f44835..3f7fcd0 100644 --- a/srcs/signals/signals_handle.c +++ b/srcs/signals/signals_handle.c @@ -38,10 +38,13 @@ int signals_handle(pid_t pid, int *cont_signal, analysis_routine_data_t *analysi } if (should_log && analysis_state->status == EXECVE_ENCOUNTERED) { - ft_dprintf(STDERR_FILENO, "--- %s {si_signo=%s, si_code=%s, si_pid=%d, si_uid=%d", + ft_dprintf(STDERR_FILENO, "--- %s {si_signo=%s, si_code=%s", ft_signalname(siginfo.si_signo), ft_signalname(siginfo.si_signo), - ft_sicodename(siginfo.si_signo, siginfo.si_code), siginfo.si_pid, - siginfo.si_uid); + ft_sicodename(siginfo.si_signo, siginfo.si_code)); + if (siginfo.si_signo == SIGSEGV) + ft_dprintf(STDERR_FILENO, ", si_addr=%p", siginfo.si_addr); + else + ft_dprintf(STDERR_FILENO, ", si_pid=%d, si_uid=%d", siginfo.si_pid, siginfo.si_uid); if (siginfo.si_signo == SIGCHLD) ft_dprintf(STDERR_FILENO, ", si_status=%d, si_utime=%ld, si_stime=%ld", siginfo.si_status, siginfo.si_utime, siginfo.si_stime); diff --git a/srcs/syscall/param_log/log_sigset_struct.c b/srcs/syscall/param_log/log_sigset_struct.c index 2994bec..bf385c1 100644 --- a/srcs/syscall/param_log/log_sigset_struct.c +++ b/srcs/syscall/param_log/log_sigset_struct.c @@ -22,7 +22,8 @@ const char *skip_sigprefix(const char *str) return str; } -#define NB_SIG 32 + +#define NB_SIG 65 /** * @brief Log sigset in local memory @@ -34,7 +35,7 @@ int log_local_sigset_struct(sigset_t *sigset) { int size_written = ft_dprintf(STDERR_FILENO, "["); bool_t first = true; - for (int i = 2; i < NB_SIG; i++) + for (unsigned i = 2; i < NB_SIG; i++) { if (sigismember(sigset, i)) {