From: Timo Sirainen Date: Tue, 3 Oct 2017 11:51:16 +0000 (+0300) Subject: lib-master: master_service_init_log() - Switch log handlers only on the first call X-Git-Tag: 2.3.0.rc1~941 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=719abeb2088987f213a33a7dd1fe78958beaef03;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-master/master-service-private.h b/src/lib-master/master-service-private.h index 409dc8972f..b117b7c13f 100644 --- a/src/lib-master/master-service-private.h +++ b/src/lib-master/master-service-private.h @@ -83,6 +83,7 @@ struct master_service { bool want_ssl_settings:1; bool ssl_ctx_initialized:1; bool config_path_from_master:1; + bool log_initialized:1; }; void master_service_io_listeners_add(struct master_service *service); diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index d1e7707119..19bfcd218d 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -353,9 +353,13 @@ void master_service_init_log(struct master_service *service, 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); @@ -363,6 +367,12 @@ void master_service_init_log(struct master_service *service, 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(); diff --git a/src/lib-master/master-service.h b/src/lib-master/master-service.h index 51b4e0207b..ac5eaa84bd 100644 --- a/src/lib-master/master-service.h +++ b/src/lib-master/master-service.h @@ -104,7 +104,8 @@ void master_service_import_environment(const char *import_environment); 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);