From: Timo Sirainen Date: Wed, 1 Apr 2009 17:13:04 +0000 (-0400) Subject: When a process is killed, show the signal code and the sending process's pid and... X-Git-Tag: 1.2.rc1~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b70234f335410d6a8913f145d1cc9befa6f00b42;p=thirdparty%2Fdovecot%2Fcore.git When a process is killed, show the signal code and the sending process's pid and uid. --HG-- branch : HEAD --- diff --git a/src/auth/main.c b/src/auth/main.c index 7bc8e31395..af40acbe36 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -42,8 +42,12 @@ static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (si->si_signo != SIGINT) - i_warning("Killed with signal %d", si->si_signo); + if (si->si_signo != SIGINT) { + i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", + si->si_signo, dec2str(si->si_pid), + dec2str(si->si_uid), + lib_signal_code_to_str(si->si_signo, si->si_code)); + } io_loop_stop(ioloop); } diff --git a/src/deliver/deliver.c b/src/deliver/deliver.c index 619874ef25..55adc44d97 100644 --- a/src/deliver/deliver.c +++ b/src/deliver/deliver.c @@ -74,8 +74,12 @@ static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (si->si_signo != SIGINT) - i_warning("Killed with signal %d", si->si_signo); + if (si->si_signo != SIGINT) { + i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", + si->si_signo, dec2str(si->si_pid), + dec2str(si->si_uid), + lib_signal_code_to_str(si->si_signo, si->si_code)); + } io_loop_stop(current_ioloop); } diff --git a/src/dict/main.c b/src/dict/main.c index cca7894312..03151006f3 100644 --- a/src/dict/main.c +++ b/src/dict/main.c @@ -27,8 +27,12 @@ static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (si->si_signo != SIGINT) - i_warning("Killed with signal %d", si->si_signo); + if (si->si_signo != SIGINT) { + i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", + si->si_signo, dec2str(si->si_pid), + dec2str(si->si_uid), + lib_signal_code_to_str(si->si_signo, si->si_code)); + } io_loop_stop(ioloop); } diff --git a/src/imap/main.c b/src/imap/main.c index a154097c94..af4815067d 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -56,8 +56,12 @@ static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (si->si_signo != SIGINT) - i_warning("Killed with signal %d", si->si_signo); + if (si->si_signo != SIGINT) { + i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", + si->si_signo, dec2str(si->si_pid), + dec2str(si->si_uid), + lib_signal_code_to_str(si->si_signo, si->si_code)); + } io_loop_stop(ioloop); } diff --git a/src/lib/lib-signals.c b/src/lib/lib-signals.c index 787b4f8a30..e96cb9b39f 100644 --- a/src/lib/lib-signals.c +++ b/src/lib/lib-signals.c @@ -27,6 +27,42 @@ static int sig_pipe_fd[2] = { -1, -1 }; static bool signals_initialized = FALSE; static struct io *io_sig = NULL; +const char *lib_signal_code_to_str(int signo, int si_code) +{ + /* common */ + switch (si_code) { + case SI_USER: + return "kill"; +#ifdef SI_KERNEL + case SI_KERNEL: + return "kernel"; +#endif + case SI_TIMER: + return "timer"; + } + + switch (signo) { + case SIGSEGV: + switch (si_code) { + case SEGV_MAPERR: + return "address not mapped"; + case SEGV_ACCERR: + return "invalid permissions"; + } + break; + case SIGBUS: + switch (si_code) { + case BUS_ADRALN: + return "invalid address alignment"; + case BUS_ADRERR: + return "nonexistent physical address"; + case BUS_OBJERR: + return "object-specific hardware error"; + } + } + return t_strdup_printf("unknown %d", si_code); +} + static void sig_handler(int signo, siginfo_t *si, void *context ATTR_UNUSED) { struct signal_handler *h; diff --git a/src/lib/lib-signals.h b/src/lib/lib-signals.h index 59ff38c1f2..273d7b8ed4 100644 --- a/src/lib/lib-signals.h +++ b/src/lib/lib-signals.h @@ -5,6 +5,9 @@ typedef void signal_handler_t(const siginfo_t *si, void *context); +/* Convert si_code to string */ +const char *lib_signal_code_to_str(int signo, int si_code); + /* Set signal handler for specific signal. If delayed is TRUE, the handler will be called later, ie. not as a real signal handler. */ void lib_signals_set_handler(int signo, bool delayed, diff --git a/src/login-common/main.c b/src/login-common/main.c index f88924ff0b..03598aaf05 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -71,8 +71,12 @@ static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (si->si_signo != SIGINT) - i_warning("Killed with signal %d", si->si_signo); + if (si->si_signo != SIGINT) { + i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", + si->si_signo, dec2str(si->si_pid), + dec2str(si->si_uid), + lib_signal_code_to_str(si->si_signo, si->si_code)); + } io_loop_stop(ioloop); } diff --git a/src/master/main.c b/src/master/main.c index a9aff73b1e..f431a7e7cf 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -170,8 +170,12 @@ static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (si->si_signo != SIGINT) - i_warning("Killed with signal %d", si->si_signo); + if (si->si_signo != SIGINT) { + i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", + si->si_signo, dec2str(si->si_pid), + dec2str(si->si_uid), + lib_signal_code_to_str(si->si_signo, si->si_code)); + } io_loop_stop(ioloop); } diff --git a/src/pop3/main.c b/src/pop3/main.c index bcbf088d92..c0bb229fca 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -56,8 +56,12 @@ static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (si->si_signo != SIGINT) - i_warning("Killed with signal %d", si->si_signo); + if (si->si_signo != SIGINT) { + i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", + si->si_signo, dec2str(si->si_pid), + dec2str(si->si_uid), + lib_signal_code_to_str(si->si_signo, si->si_code)); + } io_loop_stop(ioloop); }