changeset 12407:e2a880387cca

liblib: Delay sending log prefix updates until it's needed. This avoids sending them unnecessarily.
author Timo Sirainen <tss@iki.fi>
date Tue, 09 Nov 2010 20:25:36 +0000
parents fa911bf1cbee
children 631e0d846e57
files src/lib/failures.c
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/failures.c	Tue Nov 09 20:24:12 2010 +0000
+++ b/src/lib/failures.c	Tue Nov 09 20:25:36 2010 +0000
@@ -42,7 +42,7 @@
 static int log_fd = STDERR_FILENO, log_info_fd = STDERR_FILENO,
 	   log_debug_fd = STDERR_FILENO;
 static char *log_prefix = NULL, *log_stamp_format = NULL;
-static bool failure_ignore_errors = FALSE;
+static bool failure_ignore_errors = FALSE, log_prefix_sent = FALSE;
 
 static void ATTR_FORMAT(2, 0)
 i_internal_error_handler(const struct failure_context *ctx,
@@ -523,7 +523,7 @@
 	i_free(log_prefix);
 	log_prefix = i_strdup(prefix);
 
-	i_failure_send_option("prefix", prefix);
+	log_prefix_sent = FALSE;
 }
 
 static int internal_send_split(string_t *full_str, unsigned int prefix_len)
@@ -565,6 +565,11 @@
 		string_t *str;
 		unsigned int prefix_len;
 
+		if (!log_prefix_sent) {
+			log_prefix_sent = TRUE;
+			i_failure_send_option("prefix", log_prefix);
+		}
+
 		str = t_str_new(128);
 		str_printfa(str, "\001%c%s ", ctx->type + 1, my_pid);
 		prefix_len = str_len(str);