changeset 8883:5361cb6afe9e HEAD

When a process is killed, show the signal code and the sending process's pid and uid.
author Timo Sirainen <tss@iki.fi>
date Wed, 01 Apr 2009 13:13:04 -0400
parents 9f3968f49ceb
children ec8e679294d0
files src/auth/main.c src/deliver/deliver.c src/dict/main.c src/imap/main.c src/lib/lib-signals.c src/lib/lib-signals.h src/login-common/main.c src/master/main.c src/pop3/main.c
diffstat 9 files changed, 81 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/main.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/auth/main.c	Wed Apr 01 13:13:04 2009 -0400
@@ -42,8 +42,12 @@
 {
 	/* 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);
 }
 
--- a/src/deliver/deliver.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/deliver/deliver.c	Wed Apr 01 13:13:04 2009 -0400
@@ -74,8 +74,12 @@
 {
 	/* 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);
 }
 
--- a/src/dict/main.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/dict/main.c	Wed Apr 01 13:13:04 2009 -0400
@@ -27,8 +27,12 @@
 {
 	/* 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);
 }
 
--- a/src/imap/main.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/imap/main.c	Wed Apr 01 13:13:04 2009 -0400
@@ -56,8 +56,12 @@
 {
 	/* 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);
 }
 
--- a/src/lib/lib-signals.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/lib/lib-signals.c	Wed Apr 01 13:13:04 2009 -0400
@@ -27,6 +27,42 @@
 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;
--- a/src/lib/lib-signals.h	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/lib/lib-signals.h	Wed Apr 01 13:13:04 2009 -0400
@@ -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,
--- a/src/login-common/main.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/login-common/main.c	Wed Apr 01 13:13:04 2009 -0400
@@ -71,8 +71,12 @@
 {
 	/* 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);
 }
 
--- a/src/master/main.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/master/main.c	Wed Apr 01 13:13:04 2009 -0400
@@ -170,8 +170,12 @@
 {
 	/* 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);
 }
 
--- a/src/pop3/main.c	Wed Apr 01 12:52:46 2009 -0400
+++ b/src/pop3/main.c	Wed Apr 01 13:13:04 2009 -0400
@@ -56,8 +56,12 @@
 {
 	/* 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);
 }