dovecot-2.0: log: Avoid calling time() unnecessary when logging ...
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/80097e5c38e9
changeset: 12277:80097e5c38e9
user: Timo Sirainen <tss at iki.fi>
date: Fri Oct 15 16:09:13 2010 +0100
description:
log: Avoid calling time() unnecessary when logging multiple lines.
diffstat:
src/log/log-connection.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diffs (48 lines):
diff -r e68366e88099 -r 80097e5c38e9 src/log/log-connection.c
--- a/src/log/log-connection.c Fri Oct 15 16:08:12 2010 +0100
+++ b/src/log/log-connection.c Fri Oct 15 16:09:13 2010 +0100
@@ -122,7 +122,8 @@
}
}
-static void log_it(struct log_connection *log, const char *line)
+static void
+log_it(struct log_connection *log, const char *line, const struct tm *tm)
{
struct failure_line failure;
struct failure_context failure_ctx;
@@ -153,6 +154,7 @@
memset(&failure_ctx, 0, sizeof(failure_ctx));
failure_ctx.type = failure.log_type;
+ failure_ctx.timestamp = tm;
prefix = client != NULL && client->prefix != NULL ?
client->prefix : log->default_prefix;
@@ -210,6 +212,9 @@
static void log_connection_input(struct log_connection *log)
{
const char *line;
+ ssize_t ret;
+ time_t now;
+ struct tm tm;
if (!log->handshaked) {
if (log_connection_handshake(log) < 0) {
@@ -218,8 +223,14 @@
}
}
- while ((line = i_stream_read_next_line(log->input)) != NULL)
- log_it(log, line);
+ while ((ret = i_stream_read(log->input)) > 0 || ret == -2) {
+ /* get new timestamps for every read() */
+ now = time(NULL);
+ tm = *localtime(&now);
+
+ while ((line = i_stream_next_line(log->input)) != NULL)
+ log_it(log, line, &tm);
+ }
if (log->input->eof)
log_connection_destroy(log);
More information about the dovecot-cvs
mailing list