Skip to content

Commit

Permalink
lib-master: Hide connect(stats-writer) errors when running via CLI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen committed Dec 22, 2017
1 parent 7b1c748 commit aa572aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/lib-master/master-service-settings.c
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/lib-master/stats-client.c
Expand Up @@ -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;
Expand Down Expand Up @@ -307,24 +308,27 @@ 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;

if (stats_clients == NULL)
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;
Expand Down
3 changes: 2 additions & 1 deletion src/lib-master/stats-client.h
@@ -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

0 comments on commit aa572aa

Please sign in to comment.