Mercurial > dovecot > core-2.2
changeset 22605:a9d5eebb326e
lib-master: Allow a second log initialization after settings have been read.
This fixes logging with services that bypass the log service (lda or -L
parameter).
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Wed, 11 Oct 2017 13:03:51 +0300 |
parents | 98d99bf6511e |
children | e154812ec781 |
files | src/lib-master/master-service.c |
diffstat | 1 files changed, 20 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-master/master-service.c Mon Sep 11 13:48:17 2017 +0300 +++ b/src/lib-master/master-service.c Wed Oct 11 13:03:51 2017 +0300 @@ -341,40 +341,32 @@ return TRUE; } -void master_service_init_log(struct master_service *service, - const char *prefix) +static bool +master_service_try_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); i_set_failure_file("/dev/stderr", ""); - return; - } - - if (log_already_initialized) { - /* change only the prefix */ - i_set_failure_prefix("%s", prefix); - return; + return TRUE; } if (getenv("LOG_SERVICE") != NULL && !service->log_directly) { /* logging via log service */ i_set_failure_internal(); i_set_failure_prefix("%s", prefix); - return; + return TRUE; } if (service->set == NULL) { i_set_failure_file("/dev/stderr", prefix); - return; + /* may be called again after we have settings */ + return FALSE; } if (strcmp(service->set->log_path, "syslog") != 0) { @@ -416,6 +408,19 @@ i_set_debug_file(path); } i_set_failure_timestamp_format(service->set->log_timestamp); + return TRUE; +} + +void master_service_init_log(struct master_service *service, + const char *prefix) +{ + if (service->log_initialized) { + /* change only the prefix */ + i_set_failure_prefix("%s", prefix); + return; + } + if (master_service_try_init_log(service, prefix)) + service->log_initialized = TRUE; } void master_service_set_die_with_master(struct master_service *service,