changeset 22558:a9c51256847e

lib-master: master_service_init_log() - Switch log handlers only on the first call The secondary calls were only done by mail_storage_service_*() calls. They want to initialize the logging once, but afterwards they only care about changing the log prefix. Switch to this behavior now explicitly. This fixes behavior if logging functions are changed between mail_storage_service_*() calls, so they don't get reset.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 03 Oct 2017 14:51:16 +0300
parents 3bc39c7ae7ff
children 29e61d343a60
files src/lib-master/master-service-private.h src/lib-master/master-service.c src/lib-master/master-service.h
diffstat 3 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-master/master-service-private.h	Thu Oct 05 12:47:17 2017 +0300
+++ b/src/lib-master/master-service-private.h	Tue Oct 03 14:51:16 2017 +0300
@@ -82,6 +82,7 @@
 	unsigned int want_ssl_settings:1;
 	unsigned int ssl_ctx_initialized:1;
 	unsigned int config_path_from_master:1;
+	unsigned int log_initialized:1;
 };
 
 void master_service_io_listeners_add(struct master_service *service);
--- a/src/lib-master/master-service.c	Thu Oct 05 12:47:17 2017 +0300
+++ b/src/lib-master/master-service.c	Tue Oct 03 14:51:16 2017 +0300
@@ -345,9 +345,13 @@
 			     const char *prefix)
 {
 	const char *path, *timestamp;
+	bool log_already_initialized = service->log_initialized;
 
+	service->log_initialized = TRUE;
 	if ((service->flags & MASTER_SERVICE_FLAG_STANDALONE) != 0 &&
 	    (service->flags & MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR) == 0) {
+		if (log_already_initialized)
+			return;
 		timestamp = getenv("LOG_STDERR_TIMESTAMP");
 		if (timestamp != NULL)
 			i_set_failure_timestamp_format(timestamp);
@@ -355,6 +359,12 @@
 		return;
 	}
 
+	if (log_already_initialized) {
+		/* change only the prefix */
+		i_set_failure_prefix("%s", prefix);
+		return;
+	}
+
 	if (getenv("LOG_SERVICE") != NULL && !service->log_directly) {
 		/* logging via log service */
 		i_set_failure_internal();
--- a/src/lib-master/master-service.h	Thu Oct 05 12:47:17 2017 +0300
+++ b/src/lib-master/master-service.h	Tue Oct 03 14:51:16 2017 +0300
@@ -100,7 +100,8 @@
    DOVECOT_PRESERVE_ENVS environment. */
 void master_service_env_clean(void);
 
-/* Initialize logging. */
+/* Initialize logging. Only the first call changes the actual logging
+   functions. The following calls change the log prefix. */
 void master_service_init_log(struct master_service *service,
 			     const char *prefix);