Skip to content

Commit

Permalink
🐛 fix signal logging
Browse files Browse the repository at this point in the history
  • Loading branch information
froz42 committed Nov 5, 2023
1 parent a80d914 commit d407b67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion libft/srcs/string/ft_signalname.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <macros.h>
#include <signal.h>
#include <stddef.h>
#include <ft_printf.h>

#define SIGNAL_NAME(signalname) [signalname] = #signalname

Expand Down Expand Up @@ -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;
}
9 changes: 6 additions & 3 deletions srcs/signals/signals_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions srcs/syscall/param_log/log_sigset_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
{
Expand Down

0 comments on commit d407b67

Please sign in to comment.