]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
replication: aggregator - Replace i_<log>() with e_<log>()
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 27 Sep 2022 14:33:24 +0000 (14:33 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 26 Oct 2022 16:35:08 +0000 (16:35 +0000)
src/replication/aggregator/notify-connection.c
src/replication/aggregator/replicator-connection.c

index f9587fe9e5518cb70a591d6e6b263f383d716bb9..80dc05b590fc8b12c57ede64a25ec5873dd2cb1e 100644 (file)
@@ -19,6 +19,7 @@
 
 struct notify_connection {
        struct notify_connection *prev, *next;
+       struct event *event;
        int refcount;
 
        int fd;
@@ -49,7 +50,8 @@ void notify_connection_sync_callback(bool success, void *context)
 }
 
 static int
-notify_input_line(struct notify_connection *conn, const char *line)
+notify_input_line(struct notify_connection *conn, const char *line,
+                 const char **error_r)
 {
        const char *const *args;
        enum replication_priority priority;
@@ -57,11 +59,12 @@ notify_input_line(struct notify_connection *conn, const char *line)
        /* <username> \t <priority> */
        args = t_strsplit_tabescaped(line);
        if (str_array_length(args) < 2) {
-               i_error("Client sent invalid input");
+               *error_r = "Client sent invalid input";
                return -1;
        }
        if (replication_priority_parse(args[1], &priority) < 0) {
-               i_error("Client sent invalid priority: %s", args[1]);
+               *error_r = t_strdup_printf(
+                       "Client sent invalid priority: %s", args[1]);
                return -1;
        }
        if (priority != REPLICATION_PRIORITY_SYNC)
@@ -77,11 +80,12 @@ static void notify_input(struct notify_connection *conn)
 {
        const char *line;
        int ret;
+       const char *error;
 
        switch (i_stream_read(conn->input)) {
        case -2:
                /* buffer full */
-               i_error("Client sent too long line");
+               e_error(conn->event, "Client sent too long line");
                (void)notify_input_error(conn);
                return;
        case -1:
@@ -92,7 +96,9 @@ static void notify_input(struct notify_connection *conn)
 
        while ((line = i_stream_next_line(conn->input)) != NULL) {
                T_BEGIN {
-                       ret = notify_input_line(conn, line);
+                       ret = notify_input_line(conn, line, &error);
+                       if (ret < 0)
+                               e_error(conn->event, "%s", error);
                } T_END;
                if (ret < 0) {
                        if (!notify_input_error(conn))
@@ -110,6 +116,7 @@ void notify_connection_create(int fd, bool fifo)
        conn->fd = fd;
        conn->io = io_add(fd, IO_READ, notify_input, conn);
        conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
+       conn->event = event_create(NULL);
        if (!fifo) {
                conn->output = o_stream_create_fd(fd, SIZE_MAX);
                o_stream_set_no_error_handling(conn->output, TRUE);
@@ -126,6 +133,7 @@ static void notify_connection_unref(struct notify_connection *conn)
 
        i_stream_destroy(&conn->input);
        o_stream_destroy(&conn->output);
+       event_unref(&conn->event);
        i_free(conn);
 }
 
index 92753766856d0c5cc530542fe76c8748eb1b0fcb..b5900db94b322ebe50be69d661d65b58a4382b9a 100644 (file)
@@ -18,6 +18,7 @@
 
 struct replicator_connection {
        char *path;
+       struct event *event;
        struct ip_addr *ips;
        unsigned int ips_count, ip_idx;
        in_port_t port;
@@ -46,13 +47,13 @@ replicator_input_line(struct replicator_connection *conn, const char *line)
        /* <+|-> \t <id> */
        if ((line[0] != '+' && line[0] != '-') || line[1] != '\t' ||
            str_to_uint(line+2, &id) < 0 || id == 0) {
-               i_error("Replicator sent invalid input: %s", line);
+               e_error(conn->event, "Replicator sent invalid input: %s", line);
                return -1;
        }
 
        context = hash_table_lookup(conn->requests, POINTER_CAST(id));
        if (context == NULL) {
-               i_error("Replicator sent invalid ID: %u", id);
+               e_error(conn->event, "Replicator sent invalid ID: %u", id);
                return -1;
        }
        hash_table_remove(conn->requests, POINTER_CAST(id));
@@ -67,7 +68,7 @@ static void replicator_input(struct replicator_connection *conn)
        switch (i_stream_read(conn->input)) {
        case -2:
                /* buffer full */
-               i_error("Replicator sent too long line");
+               e_error(conn->event, "Replicator sent too long line");
                replicator_connection_disconnect(conn);
                return;
        case -1:
@@ -144,7 +145,8 @@ static void replicator_connection_connect(struct replicator_connection *conn)
        if (conn->port == 0) {
                fd = net_connect_unix(conn->path);
                if (fd == -1)
-                       i_error("net_connect_unix(%s) failed: %m", conn->path);
+                       e_error(conn->event, "net_connect_unix(%s) failed: %m",
+                               conn->path);
        } else {
                for (n = 0; n < conn->ips_count; n++) {
                        unsigned int idx = conn->ip_idx;
@@ -153,7 +155,7 @@ static void replicator_connection_connect(struct replicator_connection *conn)
                        fd = net_connect_ip(&conn->ips[idx], conn->port, NULL);
                        if (fd != -1)
                                break;
-                       i_error("connect(%s, %u) failed: %m",
+                       e_error(conn->event, "connect(%s, %u) failed: %m",
                                net_ip2addr(&conn->ips[idx]), conn->port);
                }
        }
@@ -209,6 +211,7 @@ static struct replicator_connection *replicator_connection_create(void)
 
        conn = i_new(struct replicator_connection, 1);
        conn->fd = -1;
+       conn->event = event_create(NULL);
        hash_table_create_direct(&conn->requests, default_pool, 0);
        for (i = REPLICATION_PRIORITY_LOW; i <= REPLICATION_PRIORITY_SYNC; i++)
                conn->queue[i] = buffer_create_dynamic(default_pool, 1024);
@@ -256,6 +259,7 @@ void replicator_connection_destroy(struct replicator_connection **_conn)
 
        timeout_remove(&conn->to);
        hash_table_destroy(&conn->requests);
+       event_unref(&conn->event);
        i_free(conn->ips);
        i_free(conn->path);
        i_free(conn);