#include <sys/types.h>
#include <sys/wait.h>
+static siginfo_t __siginfo;
static FILE *outputfile = NULL; ///< global output stream
static FILE *errfile = NULL; ///< global error stream
return NULL;
}
+ if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &__siginfo) != 0)
+ return NULL;
+
+
ptrace(PTRACE_INTERRUPT, pid, 0, 0);
stopped_pid = waitpid(pid, &status, 0);
return 0;
}
+/**
+ * @brief Get information about the signal that stopped the process
+ *
+ * @param pid pid of the live process
+ * @return 0 on success, -1 otherwise
+ */
+static int __get_signal_ptrace(pid_t pid)
+{
+ const char* const signal_table[] = {
+ [SIGHUP]="SIGHUP", [SIGINT]="SIGINT", [SIGQUIT]="SIGQUIT",
+ [SIGILL]="SIGILL", [SIGTRAP]="SIGTRAP", [SIGABRT]="SIGABRT",
+ [SIGIOT]="SIGIOT", [SIGBUS]="SIGBUS", [SIGFPE]="SIGFPE",
+ [SIGKILL]="SIGKILL", [SIGUSR1]="SIGUSR1", [SIGSEGV]="SIGSEGV",
+ [SIGUSR2]="SIGUSR2", [SIGPIPE]="SIGPIPE", [SIGALRM]="SIGALRM",
+ [SIGTERM]="SIGTERM", [SIGSTKFLT]="SIGSTKFLT", [SIGCHLD]="SIGCHLD",
+ [SIGCONT]="SIGCONT", [SIGSTOP]="SIGSTOP", [SIGTSTP]="SIGTSTP",
+ [SIGTTIN]="SIGTTIN", [SIGTTOU]="SIGTTOU", [SIGURG]="SIGURG",
+ [SIGXCPU]="SIGXCPU", [SIGXFSZ]="SIGXFSZ", [SIGVTALRM]="SIGVTALRM",
+ [SIGPROF]="SIGPROF", [SIGWINCH]="SIGWINCH", [SIGIO]="SIGIO",
+ [SIGPWR]="SIGPWR", [SIGSYS]="SIGSYS", [SIGUNUSED]="SIGUNUSED",
+ };
+
+ printf("Signal: %d\n"
+ "\t(%s)\n"
+ "\tsi_code: %d\n",
+ __siginfo.si_signo,
+ signal_table[__siginfo.si_signo],
+ __siginfo.si_code);
+ switch (__siginfo.si_code) {
+ case SI_TKILL:
+ case SI_USER:
+ printf("\tsignal sent by %s (sent by pid %d, uid %d)",
+ __siginfo.si_code == SI_TKILL ? "tkill" : "kill",
+ __siginfo.si_pid, __siginfo.si_uid);
+ break;
+ case SI_KERNEL:
+ printf("\tsignal sent by the kernel\n");
+ break;
+ }
+ return 0;
+}
+
#ifdef WITH_CORE_DUMP
/**
* @brief Helper function for updating mappings.
/* Now, get registers */
if (pid > 1) {
+ if (-1 == __get_signal_ptrace(pid))
+ return 4444;
if (-1 == __get_registers_ptrace(pid))
return 3333;
} else {