]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm director: Improve logging unexpected disconnections from director socket
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 14 Sep 2017 09:42:13 +0000 (12:42 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 18 Sep 2017 07:00:32 +0000 (10:00 +0300)
Previously it just logged "failed", which wasn't very understandable.

src/doveadm/doveadm-director.c

index 99e0cd6b63d11cda9757a3a332622e93bf01f5f4..e7e3a68dbce512ac41c3353d7a4518d283e76094 100644 (file)
@@ -136,6 +136,17 @@ cmd_director_init(struct doveadm_cmd_context *cctx)
        return ctx;
 }
 
+static void director_disconnected(struct director_context *ctx)
+{
+       i_assert(ctx->input->eof);
+       if (ctx->input->stream_errno != 0) {
+               i_error("read(%s) failed: %s", ctx->socket_path,
+                       i_stream_get_error(ctx->input));
+       } else {
+               i_error("%s unexpectedly disconnected", ctx->socket_path);
+       }
+       doveadm_exit_code = EX_TEMPFAIL;
+}
 
 static void
 cmd_director_status_user(struct director_context *ctx)
@@ -147,8 +158,7 @@ cmd_director_status_user(struct director_context *ctx)
                                           ctx->tag != NULL ? ctx->tag : ""));
        line = i_stream_read_next_line(ctx->input);
        if (line == NULL) {
-               i_error("Lookup failed");
-               doveadm_exit_code = EX_TEMPFAIL;
+               director_disconnected(ctx);
                return;
        }
 
@@ -228,10 +238,8 @@ static void cmd_director_status(struct doveadm_cmd_context *cctx)
                        }
                } T_END;
        }
-       if (line == NULL) {
-               i_error("Director disconnected unexpectedly");
-               doveadm_exit_code = EX_TEMPFAIL;
-       }
+       if (line == NULL)
+               director_disconnected(ctx);
        director_disconnect(ctx);
 }
 
@@ -433,10 +441,8 @@ static void cmd_director_map(struct doveadm_cmd_context *cctx)
                        }
                } T_END;
        }
-       if (line == NULL) {
-               i_error("Director disconnected unexpectedly");
-               doveadm_exit_code = EX_TEMPFAIL;
-       }
+       if (line == NULL)
+               director_disconnected(ctx);
 deinit:
        director_disconnect(ctx);
        hash_table_destroy(&users);
@@ -500,9 +506,10 @@ cmd_director_add_or_update(struct doveadm_cmd_context *cctx, bool update)
        }
        for (i = 0; i < ips_count; i++) {
                line = i_stream_read_next_line(ctx->input);
-               if (line == NULL || strcmp(line, "OK") != 0) {
+               if (line == NULL)
+                       director_disconnected(ctx);
+               else if (strcmp(line, "OK") != 0) {
                        i_error("%s: %s\n", net_ip2addr(&ips[i]),
-                               line == NULL ? "failed" :
                                strcmp(line, "NOTFOUND") == 0 ?
                                "doesn't exist" : line);
                        doveadm_exit_code = EX_TEMPFAIL;
@@ -554,9 +561,10 @@ cmd_director_ipcmd(const char *cmd_name, const char *success_result,
                                net_ip2addr(&ips[i]));
                        if (doveadm_exit_code == 0)
                                doveadm_exit_code = DOVEADM_EX_NOTFOUND;
-               } else if (line == NULL || strcmp(line, "OK") != 0) {
-                       i_error("%s: %s\n", net_ip2addr(&ips[i]),
-                               line == NULL ? "failed" : line);
+               } else if (line == NULL) {
+                       director_disconnected(ctx);
+               } else if (strcmp(line, "OK") != 0) {
+                       i_error("%s: %s\n", net_ip2addr(&ips[i]), line);
                        doveadm_exit_code = EX_TEMPFAIL;
                } else if (doveadm_verbose) {
                        i_info("%s: %s\n", net_ip2addr(&ips[i]), success_result);
@@ -603,8 +611,7 @@ static void cmd_director_move(struct doveadm_cmd_context *cctx)
                "USER-MOVE\t%u\t%s\n", user_hash, ip_str));
        line = i_stream_read_next_line(ctx->input);
        if (line == NULL) {
-               i_error("failed");
-               doveadm_exit_code = EX_TEMPFAIL;
+               director_disconnected(ctx);
        } else if (strcmp(line, "OK") == 0) {
                if (doveadm_verbose)
                        i_info("User hash %u moved to %s\n", user_hash, ip_str);
@@ -649,8 +656,7 @@ static void cmd_director_kick(struct doveadm_cmd_context *cctx)
 
        line = i_stream_read_next_line(ctx->input);
        if (line == NULL) {
-               i_error("failed");
-               doveadm_exit_code = EX_TEMPFAIL;
+               director_disconnected(ctx);
        } else if (strcmp(line, "OK") == 0) {
                if (doveadm_verbose)
                        i_info("User %s kicked", ctx->user);
@@ -677,8 +683,7 @@ static void cmd_director_flush_all(struct director_context *ctx)
 
        line = i_stream_read_next_line(ctx->input);
        if (line == NULL) {
-               i_error("failed");
-               doveadm_exit_code = EX_TEMPFAIL;
+               director_disconnected(ctx);
        } else if (strcmp(line, "OK") != 0) {
                i_error("failed: %s", line);
                doveadm_exit_code = EX_TEMPFAIL;
@@ -737,9 +742,10 @@ static void cmd_director_flush(struct doveadm_cmd_context *cctx)
                                net_ip2addr(&ips[i]));
                        if (doveadm_exit_code == 0)
                                doveadm_exit_code = DOVEADM_EX_NOTFOUND;
-               } else if (line == NULL || strcmp(line, "OK") != 0) {
-                       i_warning("%s: %s", net_ip2addr(&ips[i]),
-                               line == NULL ? "failed" : line);
+               } else if (line == NULL) {
+                       director_disconnected(ctx);
+               } else if (strcmp(line, "OK") != 0) {
+                       i_warning("%s: %s", net_ip2addr(&ips[i]), line);
                        doveadm_exit_code = EX_TEMPFAIL;
                } else if (doveadm_verbose) {
                        i_info("%s: flushed", net_ip2addr(&ips[i]));
@@ -797,10 +803,8 @@ static void cmd_director_dump(struct doveadm_cmd_context *cctx)
                doveadm_print(line);
                doveadm_print("");
        }
-       if (line == NULL) {
-               i_error("Director disconnected unexpectedly");
-               doveadm_exit_code = EX_TEMPFAIL;
-       }
+       if (line == NULL)
+               director_disconnected(ctx);
        director_disconnect(ctx);
 }
 
@@ -811,8 +815,7 @@ static void director_read_ok_reply(struct director_context *ctx)
 
        line = i_stream_read_next_line(ctx->input);
        if (line == NULL) {
-               i_error("Director disconnected unexpectedly");
-               doveadm_exit_code = EX_TEMPFAIL;
+               director_disconnected(ctx);
        } else if (strcmp(line, "NOTFOUND") == 0) {
                i_error("Not found");
                doveadm_exit_code = DOVEADM_EX_NOTFOUND;
@@ -904,10 +907,8 @@ static void cmd_director_ring_status(struct doveadm_cmd_context *cctx)
                        }
                } T_END;
        }
-       if (line == NULL) {
-               i_error("Director disconnected unexpectedly");
-               doveadm_exit_code = EX_TEMPFAIL;
-       }
+       if (line == NULL)
+               director_disconnected(ctx);
        director_disconnect(ctx);
 }