]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: master_service_init_log() - Switch log handlers only on the first call
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 3 Oct 2017 11:51:16 +0000 (14:51 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 3 Oct 2017 11:51:16 +0000 (14:51 +0300)
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.

src/lib-master/master-service-private.h
src/lib-master/master-service.c
src/lib-master/master-service.h

index 409dc8972f05cc613ea23a79d63f5786c8468908..b117b7c13f7d3d9936ea67e397df93bd52d434e8 100644 (file)
@@ -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);
index d1e77071199c688431ad4c74a55bdf9a72ae134e..19bfcd218d2707eb05ffa76105a145c8f8bfe1ae 100644 (file)
@@ -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();
index 51b4e0207bdf80799bd9387f1ec0f18c59ac05d3..ac5eaa84bd8a8e6c07188606d9f3f6f90e65121e 100644 (file)
@@ -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);