Mercurial > dovecot > core-2.2
diff src/doveadm/dsync/dsync-brain.c @ 16539:b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 24 Jun 2013 16:37:48 +0300 |
parents | 83bea7e1f136 |
children | 84014270ee37 |
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-brain.c Mon Jun 24 16:36:32 2013 +0300 +++ b/src/doveadm/dsync/dsync-brain.c Mon Jun 24 16:37:48 2013 +0300 @@ -4,10 +4,16 @@ #include "array.h" #include "hash.h" #include "hostpid.h" +#include "str.h" +#include "process-title.h" +#include "master-service.h" +#include "master-service-settings.h" #include "mail-namespace.h" #include "dsync-mailbox-tree.h" #include "dsync-ibc.h" #include "dsync-brain-private.h" +#include "dsync-mailbox-import.h" +#include "dsync-mailbox-export.h" #include <sys/stat.h> @@ -26,6 +32,42 @@ "done" }; +static const char *dsync_brain_get_proctitle(struct dsync_brain *brain) +{ + string_t *str = t_str_new(128); + const char *import_title, *export_title; + + str_append_c(str, '['); + str_append(str, brain->user->username); + if (brain->box == NULL) { + str_append_c(str, ' '); + str_append(str, dsync_state_names[brain->state]); + } else { + str_append_c(str, ' '); + str_append(str, mailbox_get_vname(brain->box)); + import_title = brain->box_importer == NULL ? "" : + dsync_mailbox_import_get_proctitle(brain->box_importer); + export_title = brain->box_exporter == NULL ? "" : + dsync_mailbox_export_get_proctitle(brain->box_exporter); + if (import_title[0] == '\0' && export_title[0] == '\0') { + str_printfa(str, " send:%s recv:%s", + dsync_box_state_names[brain->box_send_state], + dsync_box_state_names[brain->box_recv_state]); + } else { + if (import_title[0] != '\0') { + str_append(str, " import:"); + str_append(str, import_title); + } + if (export_title[0] != '\0') { + str_append(str, " export:"); + str_append(str, export_title); + } + } + } + str_append_c(str, ']'); + return str_c(str); +} + static void dsync_brain_run_io(void *context) { struct dsync_brain *brain = context; @@ -57,8 +99,11 @@ dsync_brain_common_init(struct mail_user *user, struct dsync_ibc *ibc) { struct dsync_brain *brain; + const struct master_service_settings *service_set; pool_t pool; + service_set = master_service_settings_get(master_service); + pool = pool_alloconly_create("dsync brain", 10240); brain = p_new(pool, struct dsync_brain, 1); brain->pool = pool; @@ -66,6 +111,7 @@ brain->ibc = ibc; brain->sync_type = DSYNC_BRAIN_SYNC_TYPE_UNKNOWN; brain->lock_fd = -1; + brain->verbose_proctitle = service_set->verbose_proctitle; hash_table_create(&brain->mailbox_states, pool, 0, guid_128_hash, guid_128_cmp); p_array_init(&brain->remote_mailbox_states, pool, 64); @@ -148,7 +194,8 @@ } struct dsync_brain * -dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc) +dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc, + bool local) { struct dsync_ibc_settings ibc_set; struct dsync_brain *brain; @@ -156,6 +203,12 @@ brain = dsync_brain_common_init(user, ibc); brain->state = DSYNC_STATE_SLAVE_RECV_HANDSHAKE; + if (local) { + /* both master and slave are running within the same process, + update the proctitle only for master. */ + brain->verbose_proctitle = FALSE; + } + memset(&ibc_set, 0, sizeof(ibc_set)); ibc_set.hostname = my_hostdomain(); dsync_ibc_send_handshake(ibc, &ibc_set); @@ -396,6 +449,9 @@ static bool dsync_brain_run_real(struct dsync_brain *brain, bool *changed_r) { + enum dsync_state orig_state = brain->state; + enum dsync_box_state orig_box_recv_state = brain->box_recv_state; + enum dsync_box_state orig_box_send_state = brain->box_send_state; bool changed = FALSE, ret = TRUE; if (brain->failed) @@ -453,7 +509,13 @@ brain->master_brain ? 'M' : 'S', dsync_state_names[brain->state], changed); } - + if (brain->verbose_proctitle) { + if (orig_state != brain->state || + orig_box_recv_state != brain->box_recv_state || + orig_box_send_state != brain->box_send_state || + ++brain->proctitle_update_counter % 100 == 0) + process_title_set(dsync_brain_get_proctitle(brain)); + } *changed_r = changed; return brain->failed ? FALSE : ret; }