]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
replication plugin: Error handling code cleanup
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 21 Dec 2016 19:33:35 +0000 (21:33 +0200)
committerGitLab <gitlab@git.dovecot.net>
Fri, 23 Dec 2016 13:23:30 +0000 (15:23 +0200)
The old code happened to work in all cases, but it was more of an accident.

src/plugins/replication/replication-plugin.c

index 141041d6cda4e218eb9332957f1f1d27482ec1ea..47f7cf936543b1965d79205636ae97ab60744ea3 100644 (file)
@@ -126,6 +126,7 @@ static int replication_notify_sync(struct mail_user *user)
        char buf[1024];
        int fd;
        ssize_t ret;
+       bool success = FALSE;
 
        fd = net_connect_unix(ruser->socket_path);
        if (fd == -1) {
@@ -141,7 +142,6 @@ static int replication_notify_sync(struct mail_user *user)
        alarm(ruser->sync_secs);
        if (write_full(fd, str_data(str), str_len(str)) < 0) {
                i_error("write(%s) failed: %m", ruser->socket_path);
-               ret = -1;
        } else {
                /* + | - */
                ret = read(fd, buf, sizeof(buf));
@@ -156,17 +156,14 @@ static int replication_notify_sync(struct mail_user *user)
                        }
                } else if (ret == 0) {
                        i_error("read(%s) failed: EOF", ruser->socket_path);
-                       ret = -1;
                } else if (buf[0] == '+') {
                        /* success */
-                       ret = 0;
+                       success = TRUE;
                } else if (buf[0] == '-') {
                        /* failure */
                        if (buf[ret-1] == '\n') ret--;
                        i_warning("replication(%s): Sync failure: %s",
                                  user->username, t_strndup(buf+1, ret-1));
-                       ret = -1;
-               } else {
                        i_warning("replication(%s): "
                                  "Remote sent invalid input: %s",
                                  user->username, t_strndup(buf, ret));
@@ -175,7 +172,7 @@ static int replication_notify_sync(struct mail_user *user)
        alarm(0);
        if (close(fd) < 0)
                i_error("close(%s) failed: %m", ruser->socket_path);
-       return ret;
+       return success ? 0 : -1;
 }
 
 static void replication_notify(struct mail_namespace *ns,