From 0eb3485b45b0233eb089c0337858a195cb341f0b Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 12 Dec 2016 12:53:36 +0200 Subject: [PATCH] dsync: Improve process title during initialization If something is hanging, this should make it clear what exactly it is. --- src/doveadm/doveadm-dsync.c | 10 +++++++++ src/doveadm/dsync/dsync-brain.c | 37 ++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/doveadm/doveadm-dsync.c b/src/doveadm/doveadm-dsync.c index fbe598563c..d3f4376cfd 100644 --- a/src/doveadm/doveadm-dsync.c +++ b/src/doveadm/doveadm-dsync.c @@ -14,6 +14,7 @@ #include "str.h" #include "strescape.h" #include "var-expand.h" +#include "process-title.h" #include "settings-parser.h" #include "imap-util.h" #include "master-service.h" @@ -811,6 +812,10 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx, ioloop = io_loop_create(); + if (doveadm_verbose_proctitle) { + process_title_set(t_strdup_printf( + "[dsync - connecting to %s]", server->name)); + } if (server_connection_create(server, &conn) < 0) { *error_r = "Couldn't create server connection"; return -1; @@ -828,6 +833,11 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx, str_append(cmd, "\t-U"); str_append_c(cmd, '\n'); + if (doveadm_verbose_proctitle) { + process_title_set(t_strdup_printf( + "[dsync - running dsync-server on %s]", server->name)); + } + ctx->tcp_conn = conn; server_connection_cmd(conn, str_c(cmd), NULL, dsync_connected_callback, ctx); diff --git a/src/doveadm/dsync/dsync-brain.c b/src/doveadm/dsync/dsync-brain.c index f8c822cb92..d6e584594d 100644 --- a/src/doveadm/dsync/dsync-brain.c +++ b/src/doveadm/dsync/dsync-brain.c @@ -18,6 +18,11 @@ #include +enum dsync_brain_title { + DSYNC_BRAIN_TITLE_NONE = 0, + DSYNC_BRAIN_TITLE_LOCKING, +}; + static const char *dsync_state_names[] = { "master_recv_handshake", "slave_recv_handshake", @@ -36,7 +41,9 @@ static const char *dsync_state_names[] = { static void dsync_brain_mailbox_states_dump(struct dsync_brain *brain); -static const char *dsync_brain_get_proctitle(struct dsync_brain *brain) +static const char * +dsync_brain_get_proctitle_full(struct dsync_brain *brain, + enum dsync_brain_title title) { string_t *str = t_str_new(128); const char *import_title, *export_title; @@ -70,10 +77,22 @@ static const char *dsync_brain_get_proctitle(struct dsync_brain *brain) } } } + switch (title) { + case DSYNC_BRAIN_TITLE_NONE: + break; + case DSYNC_BRAIN_TITLE_LOCKING: + str_append(str, " locking "DSYNC_LOCK_FILENAME); + break; + } str_append_c(str, ']'); return str_c(str); } +static const char *dsync_brain_get_proctitle(struct dsync_brain *brain) +{ + return dsync_brain_get_proctitle_full(brain, DSYNC_BRAIN_TITLE_NONE); +} + static void dsync_brain_run_io(void *context) { struct dsync_brain *brain = context; @@ -251,6 +270,9 @@ dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc, dsync_ibc_set_io_callback(ibc, dsync_brain_run_io, brain); brain->state = DSYNC_STATE_MASTER_RECV_HANDSHAKE; + + if (brain->verbose_proctitle) + process_title_set(dsync_brain_get_proctitle(brain)); return brain; } @@ -277,6 +299,8 @@ dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc, ibc_set.hostname = my_hostdomain(); dsync_ibc_send_handshake(ibc, &ibc_set); + if (brain->verbose_proctitle) + process_title_set(dsync_brain_get_proctitle(brain)); dsync_ibc_set_io_callback(ibc, dsync_brain_run_io, brain); return brain; } @@ -380,6 +404,8 @@ dsync_brain_lock(struct dsync_brain *brain, const char *remote_hostname) return -1; } + if (brain->verbose_proctitle) + process_title_set(dsync_brain_get_proctitle_full(brain, DSYNC_BRAIN_TITLE_LOCKING)); brain->lock_path = p_strconcat(brain->pool, home, "/"DSYNC_LOCK_FILENAME, NULL); for (;;) { @@ -387,7 +413,7 @@ dsync_brain_lock(struct dsync_brain *brain, const char *remote_hostname) if (brain->lock_fd == -1) { i_error("Couldn't create lock %s: %m", brain->lock_path); - return -1; + break; } if (file_wait_lock(brain->lock_fd, brain->lock_path, F_WRLCK, @@ -413,12 +439,17 @@ dsync_brain_lock(struct dsync_brain *brain, const char *remote_hostname) } } else if (st1.st_ino == st2.st_ino) { /* success */ + if (brain->verbose_proctitle) + process_title_set(dsync_brain_get_proctitle(brain)); return 0; } /* file was recreated, try again */ i_close_fd(&brain->lock_fd); } - i_close_fd(&brain->lock_fd); + if (brain->lock_fd != -1) + i_close_fd(&brain->lock_fd); + if (brain->verbose_proctitle) + process_title_set(dsync_brain_get_proctitle(brain)); return -1; }