Mercurial > dovecot > core-2.2
changeset 10192:585bceaf98bb HEAD
imap: Added support for verbose_proctitle=yes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 26 Oct 2009 19:49:22 -0400 |
parents | b57588b298aa |
children | 02e852b2c2c3 |
files | src/imap/imap-client.c src/imap/imap-client.h src/imap/imap-common.h src/imap/imap-settings.c src/imap/imap-settings.h src/imap/main.c |
diffstat | 6 files changed, 59 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/imap-client.c Mon Oct 26 19:46:48 2009 -0400 +++ b/src/imap/imap-client.c Mon Oct 26 19:49:22 2009 -0400 @@ -23,6 +23,7 @@ struct imap_module_register imap_module_register = { 0 }; struct client *imap_clients = NULL; +unsigned int imap_client_count = 0; static void client_idle_timeout(struct client *client) { @@ -77,9 +78,12 @@ client->anvil_sent = TRUE; } + imap_client_count++; DLLIST_PREPEND(&imap_clients, client); if (hook_client_created != NULL) hook_client_created(&client); + + imap_refresh_proctitle(); return client; } @@ -160,6 +164,7 @@ i_info("%s %s", reason, client_stats(client)); } + imap_client_count--; DLLIST_REMOVE(&imap_clients, client); i_stream_close(client->input); @@ -219,6 +224,7 @@ i_free(client); master_service_client_connection_destroyed(master_service); + imap_refresh_proctitle(); } void client_disconnect(struct client *client, const char *reason) @@ -529,6 +535,7 @@ if (client->to_idle_output != NULL) timeout_remove(&client->to_idle_output); } + imap_refresh_proctitle(); } static void client_add_missing_io(struct client *client) @@ -656,6 +663,7 @@ if (cmd->name == NULL) return FALSE; /* need more data */ cmd->name = p_strdup(cmd->pool, cmd->name); + imap_refresh_proctitle(); } client->input_skip_line = TRUE;
--- a/src/imap/imap-client.h Mon Oct 26 19:46:48 2009 -0400 +++ b/src/imap/imap-client.h Mon Oct 26 19:49:22 2009 -0400 @@ -148,6 +148,7 @@ }; extern struct client *imap_clients; +extern unsigned int imap_client_count; /* Create new client with specified input/output handles. socket specifies if the handle is a socket. */
--- a/src/imap/imap-common.h Mon Oct 26 19:46:48 2009 -0400 +++ b/src/imap/imap-common.h Mon Oct 26 19:49:22 2009 -0400 @@ -19,4 +19,6 @@ extern void (*hook_client_created)(struct client **client); +void imap_refresh_proctitle(void); + #endif
--- a/src/imap/imap-settings.c Mon Oct 26 19:46:48 2009 -0400 +++ b/src/imap/imap-settings.c Mon Oct 26 19:49:22 2009 -0400 @@ -60,6 +60,7 @@ static const struct setting_define imap_setting_defines[] = { DEF(SET_BOOL, mail_debug), + DEF(SET_BOOL, verbose_proctitle), DEF(SET_UINT, imap_max_line_length), DEF(SET_UINT, imap_idle_notify_interval), @@ -74,6 +75,7 @@ static const struct imap_settings imap_default_settings = { MEMBER(mail_debug) FALSE, + MEMBER(verbose_proctitle) FALSE, /* RFC-2683 recommends at least 8000 bytes. Some clients however don't break large message sets to multiple commands, so we're pretty
--- a/src/imap/imap-settings.h Mon Oct 26 19:46:48 2009 -0400 +++ b/src/imap/imap-settings.h Mon Oct 26 19:49:22 2009 -0400 @@ -13,6 +13,7 @@ struct imap_settings { bool mail_debug; + bool verbose_proctitle; /* imap: */ unsigned int imap_max_line_length;
--- a/src/imap/main.c Mon Oct 26 19:46:48 2009 -0400 +++ b/src/imap/main.c Mon Oct 26 19:49:22 2009 -0400 @@ -6,6 +6,7 @@ #include "ostream.h" #include "str.h" #include "base64.h" +#include "process-title.h" #include "restrict-access.h" #include "fd-close-on-exec.h" #include "master-interface.h" @@ -25,11 +26,52 @@ #define IMAP_DIE_IDLE_SECS 10 +static bool verbose_proctitle = FALSE; static struct mail_storage_service_ctx *storage_service; static struct master_login *master_login = NULL; void (*hook_client_created)(struct client **client) = NULL; +void imap_refresh_proctitle(void) +{ +#define IMAP_PROCTITLE_PREFERRED_LEN 80 + struct client *client; + struct client_command_context *cmd; + string_t *title = t_str_new(128); + + if (!verbose_proctitle) + return; + + str_append_c(title, '['); + switch (imap_client_count) { + case 0: + str_append(title, "idling"); + break; + case 1: + client = imap_clients; + str_append(title, client->user->username); + if (client->user->remote_ip != NULL) { + str_append_c(title, ' '); + str_append(title, net_ip2addr(client->user->remote_ip)); + } + for (cmd = client->command_queue; cmd != NULL; cmd = cmd->next) { + if (cmd->name == NULL) + continue; + + if (str_len(title) > IMAP_PROCTITLE_PREFERRED_LEN) + break; + str_append_c(title, ' '); + str_append(title, cmd->name); + } + break; + default: + str_printfa(title, "%u connections", imap_client_count); + break; + } + str_append_c(title, ']'); + process_title_set(str_c(title)); +} + static void client_kill_idle(struct client *client) { if (client->output_lock != NULL) @@ -130,6 +172,9 @@ restrict_access_allow_coredumps(TRUE); set = mail_storage_service_user_get_set(user)[1]; + if (set->verbose_proctitle) + verbose_proctitle = TRUE; + client = client_create(fd_in, fd_out, mail_user, user, set); T_BEGIN { client_add_input(client, input_buf);