diff src/pop3/main.c @ 10193:02e852b2c2c3 HEAD

pop3: Added support for verbose_proctitle=yes
author Timo Sirainen <tss@iki.fi>
date Mon, 26 Oct 2009 19:53:48 -0400
parents 7f0ccd367351
children 40d8df2b4111
line wrap: on
line diff
--- 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,11 +23,41 @@
 #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)
 {
 	/* do nothing. pop3 connections typically die pretty quick anyway. */
@@ -65,6 +98,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);