From: Timo Sirainen Date: Fri, 22 Dec 2017 11:20:41 +0000 (+0200) Subject: lib-master: Add master_service_init_stats_client() X-Git-Tag: 2.3.9~2618 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6f23086d0259d50cde3bd5d4180d67d820d293d;p=thirdparty%2Fdovecot%2Fcore.git lib-master: Add master_service_init_stats_client() This allows initializing the stats client after master_service_init() if necessary. --- diff --git a/src/lib-master/master-service-settings.c b/src/lib-master/master-service-settings.c index 925d63c171..13607c8113 100644 --- a/src/lib-master/master-service-settings.c +++ b/src/lib-master/master-service-settings.c @@ -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); diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 3bec33b049..6428edb393 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -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) { diff --git a/src/lib-master/master-service.h b/src/lib-master/master-service.h index ad07194cac..eafb0d51ba 100644 --- a/src/lib-master/master-service.h +++ b/src/lib-master/master-service.h @@ -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. */