From: Timo Sirainen Date: Fri, 15 Oct 2010 15:09:13 +0000 (+0100) Subject: log: Avoid calling time() unnecessary when logging multiple lines. X-Git-Tag: 2.0.6~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19c587fe07581d654721efb724ccc7fa8513abd6;p=thirdparty%2Fdovecot%2Fcore.git log: Avoid calling time() unnecessary when logging multiple lines. --- diff --git a/src/log/log-connection.c b/src/log/log-connection.c index b71c757c06..ff1da2132f 100644 --- a/src/log/log-connection.c +++ b/src/log/log-connection.c @@ -122,7 +122,8 @@ static void log_parse_master_line(const char *line) } } -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 @@ static void log_it(struct log_connection *log, const char *line) 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 int log_connection_handshake(struct log_connection *log) 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 @@ static void log_connection_input(struct log_connection *log) } } - 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);