dovecot-2.0: Failure logging supports now getting timestamp as p...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Oct 15 18:09:17 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/e68366e88099
changeset: 12276:e68366e88099
user: Timo Sirainen <tss at iki.fi>
date: Fri Oct 15 16:08:12 2010 +0100
description:
Failure logging supports now getting timestamp as parameter.
diffstat:
src/lib/failures.c | 23 ++++++++++++-----------
src/lib/failures.h | 1 +
2 files changed, 13 insertions(+), 11 deletions(-)
diffs (77 lines):
diff -r 4933c3095ee2 -r e68366e88099 src/lib/failures.c
--- a/src/lib/failures.c Fri Oct 15 15:46:43 2010 +0100
+++ b/src/lib/failures.c Fri Oct 15 16:08:12 2010 +0100
@@ -64,15 +64,17 @@
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 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 @@
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 @@
{
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 @@
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 -r 4933c3095ee2 -r e68366e88099 src/lib/failures.h
--- a/src/lib/failures.h Fri Oct 15 15:46:43 2010 +0100
+++ b/src/lib/failures.h Fri Oct 15 16:08:12 2010 +0100
@@ -35,6 +35,7 @@
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 "
More information about the dovecot-cvs
mailing list