From: Timo Sirainen Date: Fri, 15 Oct 2010 15:08:12 +0000 (+0100) Subject: Failure logging supports now getting timestamp as parameter. X-Git-Tag: 2.0.6~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8882cee80439046d678f08c52f0584bd92c7d361;p=thirdparty%2Fdovecot%2Fcore.git Failure logging supports now getting timestamp as parameter. --- diff --git a/src/lib/failures.c b/src/lib/failures.c index 8807dd4852..e27c5ae9c4 100644 --- a/src/lib/failures.c +++ b/src/lib/failures.c @@ -64,15 +64,17 @@ void failure_exit(int status) exit(status); } -static void log_prefix_add(string_t *str) +static void log_prefix_add(const struct failure_context *ctx, string_t *str) { - struct tm *tm; + const struct tm *tm = ctx->timestamp; char buf[256]; time_t now; if (log_stamp_format != NULL) { - now = time(NULL); - tm = localtime(&now); + if (tm == NULL) { + now = time(NULL); + tm = localtime(&now); + } if (strftime(buf, sizeof(buf), get_log_stamp_format("unused"), tm) > 0) @@ -139,7 +141,8 @@ static int log_fd_write(int fd, const unsigned char *data, unsigned int len) } static int ATTR_FORMAT(3, 0) -default_handler(const char *prefix, int fd, const char *format, va_list args) +default_handler(const struct failure_context *ctx, int fd, + const char *format, va_list args) { static int recursed = 0; int ret; @@ -153,8 +156,8 @@ default_handler(const char *prefix, int fd, const char *format, va_list args) recursed++; T_BEGIN { string_t *str = t_str_new(256); - log_prefix_add(str); - str_append(str, prefix); + log_prefix_add(ctx, str); + str_append(str, failure_log_type_prefixes[ctx->type]); /* make sure there's no %n in there and fix %m */ str_vprintfa(str, printf_format_fix(format), args); @@ -191,8 +194,7 @@ void default_fatal_handler(const struct failure_context *ctx, { int status = ctx->exit_status; - if (default_handler(failure_log_type_prefixes[ctx->type], - log_fd, format, args) < 0 && + if (default_handler(ctx, log_fd, format, args) < 0 && status == FATAL_DEFAULT) status = FATAL_LOGWRITE; @@ -215,8 +217,7 @@ void default_error_handler(const struct failure_context *ctx, fd = log_fd; } - if (default_handler(failure_log_type_prefixes[ctx->type], - fd, format, args) < 0) { + if (default_handler(ctx, fd, format, args) < 0) { if (fd == log_fd) failure_exit(FATAL_LOGWRITE); /* we failed to log to info/debug log, try to log the diff --git a/src/lib/failures.h b/src/lib/failures.h index 7671703b92..9cc99e3d24 100644 --- a/src/lib/failures.h +++ b/src/lib/failures.h @@ -35,6 +35,7 @@ struct failure_line { struct failure_context { enum log_type type; int exit_status; /* for LOG_TYPE_FATAL */ + const struct tm *timestamp; /* NULL = use time() + localtime() */ }; #define DEFAULT_FAILURE_STAMP_FORMAT "%b %d %H:%M:%S "