dovecot-2.0-sslstream: pop3: 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/02e852b2c2c3
changeset: 10194:02e852b2c2c3
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 26 19:53:48 2009 -0400
description:
pop3: Added support for verbose_proctitle=yes

diffstat:

6 files changed, 48 insertions(+)
src/pop3/main.c          |   36 ++++++++++++++++++++++++++++++++++++
src/pop3/pop3-client.c   |    6 ++++++
src/pop3/pop3-client.h   |    1 +
src/pop3/pop3-common.h   |    2 ++
src/pop3/pop3-settings.c |    2 ++
src/pop3/pop3-settings.h |    1 +

diffs (160 lines):

diff -r 585bceaf98bb -r 02e852b2c2c3 src/pop3/main.c
--- a/src/pop3/main.c	Mon Oct 26 19:49:22 2009 -0400
+++ b/src/pop3/main.c	Mon Oct 26 19:53:48 2009 -0400
@@ -6,11 +6,14 @@
 #include "istream.h"
 #include "ostream.h"
 #include "base64.h"
+#include "str.h"
+#include "process-title.h"
 #include "restrict-access.h"
 #include "master-service.h"
 #include "master-login.h"
 #include "master-interface.h"
 #include "var-expand.h"
+#include "mail-user.h"
 #include "mail-storage-service.h"
 
 #include <stdio.h>
@@ -20,10 +23,40 @@
 #define IS_STANDALONE() \
         (getenv(MASTER_UID_ENV) == NULL)
 
+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 pop3_refresh_proctitle(void)
+{
+	struct client *client;
+	string_t *title = t_str_new(128);
+
+	if (!verbose_proctitle)
+		return;
+
+	str_append_c(title, '[');
+	switch (pop3_client_count) {
+	case 0:
+		str_append(title, "idling");
+		break;
+	case 1:
+		client = pop3_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));
+		}
+		break;
+	default:
+		str_printfa(title, "%u connections", pop3_client_count);
+		break;
+	}
+	str_append_c(title, ']');
+	process_title_set(str_c(title));
+}
 
 static void pop3_die(void)
 {
@@ -65,6 +98,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);
diff -r 585bceaf98bb -r 02e852b2c2c3 src/pop3/pop3-client.c
--- a/src/pop3/pop3-client.c	Mon Oct 26 19:49:22 2009 -0400
+++ b/src/pop3/pop3-client.c	Mon Oct 26 19:53:48 2009 -0400
@@ -37,6 +37,7 @@
 #define CLIENT_COMMIT_TIMEOUT_MSECS (10*1000)
 
 struct client *pop3_clients;
+unsigned int pop3_client_count;
 
 static void client_input(struct client *client);
 static int client_output(struct client *client);
@@ -266,9 +267,12 @@ struct client *client_create(int fd_in, 
 		client->anvil_sent = TRUE;
 	}
 
+	pop3_client_count++;
 	DLLIST_PREPEND(&pop3_clients, client);
 	if (hook_client_created != NULL)
 		hook_client_created(&client);
+
+	pop3_refresh_proctitle();
 	return client;
 }
 
@@ -334,6 +338,7 @@ void client_destroy(struct client *clien
 		client->cmd(client);
 		i_assert(client->cmd == NULL);
 	}
+	pop3_client_count--;
 	DLLIST_REMOVE(&pop3_clients, client);
 
 	if (client->trans != NULL) {
@@ -375,6 +380,7 @@ void client_destroy(struct client *clien
 	i_free(client);
 
 	master_service_client_connection_destroyed(master_service);
+	pop3_refresh_proctitle();
 }
 
 void client_disconnect(struct client *client, const char *reason)
diff -r 585bceaf98bb -r 02e852b2c2c3 src/pop3/pop3-client.h
--- a/src/pop3/pop3-client.h	Mon Oct 26 19:49:22 2009 -0400
+++ b/src/pop3/pop3-client.h	Mon Oct 26 19:53:48 2009 -0400
@@ -62,6 +62,7 @@ struct client {
 };
 
 extern struct client *pop3_clients;
+extern unsigned int pop3_client_count;
 
 /* Create new client with specified input/output handles. socket specifies
    if the handle is a socket. */
diff -r 585bceaf98bb -r 02e852b2c2c3 src/pop3/pop3-common.h
--- a/src/pop3/pop3-common.h	Mon Oct 26 19:49:22 2009 -0400
+++ b/src/pop3/pop3-common.h	Mon Oct 26 19:53:48 2009 -0400
@@ -14,4 +14,6 @@ enum uidl_keys {
 
 extern void (*hook_client_created)(struct client **client);
 
+void pop3_refresh_proctitle(void);
+
 #endif
diff -r 585bceaf98bb -r 02e852b2c2c3 src/pop3/pop3-settings.c
--- a/src/pop3/pop3-settings.c	Mon Oct 26 19:49:22 2009 -0400
+++ b/src/pop3/pop3-settings.c	Mon Oct 26 19:53:48 2009 -0400
@@ -60,6 +60,7 @@ struct service_settings pop3_service_set
 
 static const struct setting_define pop3_setting_defines[] = {
 	DEF(SET_BOOL, mail_debug),
+	DEF(SET_BOOL, verbose_proctitle),
 
 	DEF(SET_BOOL, pop3_no_flag_updates),
 	DEF(SET_BOOL, pop3_enable_last),
@@ -74,6 +75,7 @@ static const struct setting_define pop3_
 
 static const struct pop3_settings pop3_default_settings = {
 	MEMBER(mail_debug) FALSE,
+	MEMBER(verbose_proctitle) FALSE,
 
 	MEMBER(pop3_no_flag_updates) FALSE,
 	MEMBER(pop3_enable_last) FALSE,
diff -r 585bceaf98bb -r 02e852b2c2c3 src/pop3/pop3-settings.h
--- a/src/pop3/pop3-settings.h	Mon Oct 26 19:49:22 2009 -0400
+++ b/src/pop3/pop3-settings.h	Mon Oct 26 19:53:48 2009 -0400
@@ -12,6 +12,7 @@ enum pop3_client_workarounds {
 
 struct pop3_settings {
 	bool mail_debug;
+	bool verbose_proctitle;
 
 	/* pop3: */
 	bool pop3_no_flag_updates;


More information about the dovecot-cvs mailing list