]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: Hide connect(stats-writer) errors when running via CLI
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 22 Dec 2017 11:27:48 +0000 (13:27 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 22 Dec 2017 13:25:41 +0000 (15:25 +0200)
Only hide errors that occur if the stats process isn't running, i.e. when
socket isn't found or there's no listener. This way e.g. permission errors
are still logged, which points to a wrong configuration.

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

index a2390ea7717f3016647aecf4124e551327117c61..925d63c17118a64b353365fdb8e7ccd70a3ead10 100644 (file)
@@ -589,7 +589,13 @@ int master_service_settings_read(struct master_service *service,
                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);
+               /* 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;
 
        if (service->set->shutdown_clients)
index f07760a6a89b17d7d7a3a48e5912c55babb63c29..921d5cf7742d10ac6f9031dd8406e3f77cf1d6e6 100644 (file)
@@ -19,6 +19,7 @@ struct stats_client {
        struct timeout *to_reconnect;
        bool handshaked;
        bool handshake_received_at_least_once;
+       bool silent_notfound_errors;
 };
 
 static struct connection_list *stats_clients;
@@ -307,17 +308,19 @@ static void stats_client_send_registered_categories(struct stats_client *client)
 
 static void stats_client_connect(struct stats_client *client)
 {
-       if (connection_client_connect(&client->conn) < 0)
-               i_error("net_connect_unix(%s) failed: %m", client->conn.name);
-       else {
+       if (connection_client_connect(&client->conn) == 0) {
                /* read the handshake so the global debug filter is updated */
                stats_client_send_registered_categories(client);
                if (!client->handshake_received_at_least_once)
                        stats_client_wait_handshake(client);
+       } else if (!client->silent_notfound_errors ||
+                  (errno != ENOENT && errno != ECONNREFUSED)) {
+               i_error("net_connect_unix(%s) failed: %m", client->conn.name);
        }
 }
 
-struct stats_client *stats_client_init(const char *path)
+struct stats_client *
+stats_client_init(const char *path, bool silent_notfound_errors)
 {
        struct stats_client *client;
 
@@ -325,6 +328,7 @@ struct stats_client *stats_client_init(const char *path)
                stats_global_init();
 
        client = i_new(struct stats_client, 1);
+       client->silent_notfound_errors = silent_notfound_errors;
        connection_init_client_unix(stats_clients, &client->conn, path);
        stats_client_connect(client);
        return client;
index fb0ca082b5822162bd76786ff32a0586c7fa5448..c20bf5d8ccfb0dbabaf20a5915413ab1395c4456 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef STATS_CLIENT_H
 #define STATS_CLIENT_H
 
-struct stats_client *stats_client_init(const char *path);
+struct stats_client *
+stats_client_init(const char *path, bool silent_notfound_errors);
 void stats_client_deinit(struct stats_client **client);
 
 #endif