dovecot-2.0-sslstream: imap: Added support for verbose_proctitle...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:55:43 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/585bceaf98bb
changeset: 10193:585bceaf98bb
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 26 19:49:22 2009 -0400
description:
imap: Added support for verbose_proctitle=yes

diffstat:

6 files changed, 59 insertions(+)
src/imap/imap-client.c   |    8 ++++++++
src/imap/imap-client.h   |    1 +
src/imap/imap-common.h   |    2 ++
src/imap/imap-settings.c |    2 ++
src/imap/imap-settings.h |    1 +
src/imap/main.c          |   45 +++++++++++++++++++++++++++++++++++++++++++++

diffs (180 lines):

diff -r b57588b298aa -r 585bceaf98bb src/imap/imap-client.c
--- 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_
 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 @@ struct client *client_create(int fd_in, 
 		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 @@ void client_destroy(struct client *clien
 		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 @@ void client_destroy(struct client *clien
 	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 @@ void client_command_free(struct client_c
 		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 @@ static bool client_command_input(struct 
 		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;
diff -r b57588b298aa -r 585bceaf98bb src/imap/imap-client.h
--- 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 @@ struct client {
 };
 
 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. */
diff -r b57588b298aa -r 585bceaf98bb src/imap/imap-common.h
--- 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
diff -r b57588b298aa -r 585bceaf98bb src/imap/imap-settings.c
--- 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 @@ struct service_settings imap_service_set
 
 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 setting_define imap_
 
 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
diff -r b57588b298aa -r 585bceaf98bb src/imap/imap-settings.h
--- 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 @@ enum imap_client_workarounds {
 
 struct imap_settings {
 	bool mail_debug;
+	bool verbose_proctitle;
 
 	/* imap: */
 	unsigned int imap_max_line_length;
diff -r b57588b298aa -r 585bceaf98bb src/imap/main.c
--- 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,10 +26,51 @@
 
 #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)
 {
@@ -130,6 +172,9 @@ client_create_from_input(const struct ma
 	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);


More information about the dovecot-cvs mailing list