dovecot-1.1: Prefix fatal/panic messages with syslog.

dovecot at dovecot.org dovecot at dovecot.org
Wed Mar 5 02:17:55 EET 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/51c72fdaadfd
changeset: 7350:51c72fdaadfd
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Mar 05 02:17:33 2008 +0200
description:
Prefix fatal/panic messages with syslog.

diffstat:

1 file changed, 17 insertions(+), 8 deletions(-)
src/lib/failures.c |   25 +++++++++++++++++--------

diffs (57 lines):

diff -r 63ef0998cd53 -r 51c72fdaadfd src/lib/failures.c
--- a/src/lib/failures.c	Wed Mar 05 02:04:29 2008 +0200
+++ b/src/lib/failures.c	Wed Mar 05 02:17:33 2008 +0200
@@ -263,8 +263,8 @@ void i_set_info_handler(failure_callback
 	info_handler = callback;
 }
 
-static int ATTR_FORMAT(2, 0)
-syslog_handler(int level, const char *format, va_list args)
+static int ATTR_FORMAT(3, 0)
+syslog_handler(int level, enum log_type type, const char *format, va_list args)
 {
 	static int recursed = 0;
 
@@ -273,11 +273,19 @@ syslog_handler(int level, const char *fo
 
 	recursed++;
 
-	/* make sure there's no %n in there. vsyslog() supports %m, but since
-	   we'll convert it ourself anyway, we might as well it */
-	vsyslog(level, printf_format_fix_unsafe(format), args);
+	/* syslogs don't generatelly bother to log the level in any way,
+	   so make sure fatals and panics are shown clearly */
+	if (type == LOG_TYPE_FATAL || type == LOG_TYPE_PANIC) {
+		T_BEGIN {
+			syslog(level, "%s%s", failure_log_type_prefixes[type],
+			       t_strdup_vprintf(format, args));
+		} T_END;
+	} else {
+		/* make sure there's no %n in there. vsyslog() supports %m, but
+		   since we'll convert it ourself anyway, we might as well it */
+		vsyslog(level, printf_format_fix_unsafe(format), args);
+	}
 	recursed--;
-
 	return 0;
 }
 
@@ -285,7 +293,8 @@ void i_syslog_fatal_handler(enum log_typ
 			    const char *fmt, va_list args)
 {
 	const char *backtrace;
-	if (syslog_handler(LOG_CRIT, fmt, args) < 0 && status == FATAL_DEFAULT)
+	if (syslog_handler(LOG_CRIT, type, fmt, args) < 0 &&
+	    status == FATAL_DEFAULT)
 		status = FATAL_LOGERROR;
 
 	if (type == LOG_TYPE_PANIC) {
@@ -317,7 +326,7 @@ void i_syslog_error_handler(enum log_typ
 		break;
 	}
 
-	if (syslog_handler(level, fmt, args) < 0)
+	if (syslog_handler(level, type, fmt, args) < 0)
 		failure_exit(FATAL_LOGERROR);
 }
 


More information about the dovecot-cvs mailing list