Skip to content

Commit

Permalink
dsync: Improve process title during initialization
Browse files Browse the repository at this point in the history
If something is hanging, this should make it clear what exactly it is.
  • Loading branch information
sirainen committed Dec 12, 2016
1 parent 6af4e59 commit 0eb3485
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/doveadm/doveadm-dsync.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
37 changes: 34 additions & 3 deletions src/doveadm/dsync/dsync-brain.c
Expand Up @@ -18,6 +18,11 @@

#include <sys/stat.h>

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",
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -380,14 +404,16 @@ 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 (;;) {
brain->lock_fd = creat(brain->lock_path, 0600);
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,
Expand All @@ -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;
}

Expand Down

0 comments on commit 0eb3485

Please sign in to comment.