]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: Add master_service_init_stats_client()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 22 Dec 2017 11:20:41 +0000 (13:20 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 22 Dec 2017 13:25:41 +0000 (15:25 +0200)
This allows initializing the stats client after master_service_init() if
necessary.

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

index 925d63c17118a64b353365fdb8e7ccd70a3ead10..13607c8113e73f3f4ae9aaf319a5dac3290294b2 100644 (file)
@@ -583,20 +583,14 @@ int master_service_settings_read(struct master_service *service,
                /* running standalone. we want to ignore plugin versions. */
                service->version_string = NULL;
        }
-       if ((service->flags & MASTER_SERVICE_FLAG_SEND_STATS) != 0 &&
-           service->stats_client == NULL &&
-           service->set->stats_writer_socket_path[0] != '\0') T_BEGIN {
-               const char *path = t_strdup_printf("%s/%s",
-                       service->set->base_dir,
-                       service->set->stats_writer_socket_path);
+       if ((service->flags & MASTER_SERVICE_FLAG_SEND_STATS) != 0) {
                /* When running standalone (e.g. doveadm) try to connect to the
                   stats socket, but don't log an error if it's not running.
                   It may be intentional. */
                bool silent_notfound_errors =
                        (service->flags & MASTER_SERVICE_FLAG_STANDALONE) != 0;
-               service->stats_client =
-                       stats_client_init(path, silent_notfound_errors);
-       } T_END;
+               master_service_init_stats_client(service, silent_notfound_errors);
+       }
 
        if (service->set->shutdown_clients)
                master_service_set_die_with_master(master_service, TRUE);
index 3bec33b0495fa4115624109aeb71126945434efd..6428edb393359f7c936493807f1028d203e27c71 100644 (file)
@@ -451,6 +451,19 @@ void master_service_init_log(struct master_service *service,
                service->log_initialized = TRUE;
 }
 
+void master_service_init_stats_client(struct master_service *service,
+                                     bool silent_notfound_errors)
+{
+       if (service->stats_client == NULL &&
+           service->set->stats_writer_socket_path[0] != '\0') T_BEGIN {
+               const char *path = t_strdup_printf("%s/%s",
+                       service->set->base_dir,
+                       service->set->stats_writer_socket_path);
+               service->stats_client =
+                       stats_client_init(path, silent_notfound_errors);
+       } T_END;
+}
+
 void master_service_set_die_with_master(struct master_service *service,
                                        bool set)
 {
index ad07194cacdb836c98a33b3a220f5d7b3b87cca7..eafb0d51ba38dbf4b129c368afd104181f2ac477 100644 (file)
@@ -128,6 +128,12 @@ void master_service_env_clean(void);
    functions. The following calls change the log prefix. */
 void master_service_init_log(struct master_service *service,
                             const char *prefix);
+/* Initialize stats client (if it's not already initialized). This is called
+   automatically if MASTER_SERVICE_FLAG_SEND_STATS is enabled. If
+   silent_notfound_errors is set, connect() errors aren't logged if they're
+   happening because the stats service isn't running. */
+void master_service_init_stats_client(struct master_service *service,
+                                     bool silent_notfound_errors);
 
 /* If set, die immediately when connection to master is lost.
    Normally all existing clients are handled first. */