dovecot-2.2: lmtp: Show more information in process title.

dovecot at dovecot.org dovecot at dovecot.org
Tue Nov 11 23:27:22 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/aca0b7142046
changeset: 18061:aca0b7142046
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Nov 12 01:26:04 2014 +0200
description:
lmtp: Show more information in process title.
Most importantly show the username while messages are being delivered.

diffstat:

 src/lmtp/client.c   |  34 ++++++++++++++++++++++++----------
 src/lmtp/client.h   |   4 ++--
 src/lmtp/commands.c |  21 ++++++++++++---------
 3 files changed, 38 insertions(+), 21 deletions(-)

diffs (208 lines):

diff -r a4fbe94952ea -r aca0b7142046 src/lmtp/client.c
--- a/src/lmtp/client.c	Wed Nov 12 01:06:02 2014 +0200
+++ b/src/lmtp/client.c	Wed Nov 12 01:26:04 2014 +0200
@@ -34,18 +34,32 @@
 static struct client *clients = NULL;
 unsigned int clients_count = 0;
 
-void client_state_set(struct client *client, const char *name)
+void client_state_set(struct client *client, const char *name, const char *args)
 {
+	string_t *str;
+
 	client->state.name = name;
 
 	if (!client->service_set->verbose_proctitle)
 		return;
-	if (clients_count == 0)
+
+	if (clients_count == 0) {
 		process_title_set("[idling]");
-	else if (clients_count > 1)
+		return;
+	}
+	if (clients_count > 1) {
 		process_title_set(t_strdup_printf("[%u clients]", clients_count));
-	else
-		process_title_set(t_strdup_printf("[%s]", client->state.name));
+		return;
+	}
+
+	str = t_str_new(128);
+	str_printfa(str, "[%s", client->state.name);
+	if (client->remote_ip.family != 0)
+		str_printfa(str, " %s", net_ip2addr(&client->remote_ip));
+	if (args[0] != '\0')
+		str_printfa(str, " %s", args);
+	str_append_c(str, ']');
+	process_title_set(str_c(str));
 }
 
 static void client_idle_timeout(struct client *client)
@@ -253,7 +267,7 @@
 	DLLIST_PREPEND(&clients, client);
 	clients_count++;
 
-	client_state_set(client, "banner");
+	client_state_set(client, "banner", "");
 	client_send_line(client, "220 %s %s", client->my_domain,
 			 client->lmtp_set->login_greeting);
 	i_info("Connect from %s", client_remote_id(client));
@@ -269,7 +283,7 @@
 	clients_count--;
 	DLLIST_REMOVE(&clients, client);
 
-	client_state_set(client, "destroyed");
+	client_state_set(client, "destroyed", "");
 
 	if (client->raw_mail_user != NULL)
 		mail_user_unref(&client->raw_mail_user);
@@ -287,7 +301,7 @@
 	net_disconnect(client->fd_in);
 	if (client->fd_in != client->fd_out)
 		net_disconnect(client->fd_out);
-	client_state_reset(client);
+	client_state_reset(client, "destroyed");
 	i_free(client->lhlo);
 	pool_unref(&client->state_pool);
 	pool_unref(&client->pool);
@@ -333,7 +347,7 @@
 	client->disconnected = TRUE;
 }
 
-void client_state_reset(struct client *client)
+void client_state_reset(struct client *client, const char *state_name)
 {
 	struct mail_recipient *rcpt;
 
@@ -369,7 +383,7 @@
 	client->state.mail_data_fd = -1;
 
 	client_generate_session_id(client);
-	client_state_set(client, "reset");
+	client_state_set(client, state_name, "");
 }
 
 void client_send_line(struct client *client, const char *fmt, ...)
diff -r a4fbe94952ea -r aca0b7142046 src/lmtp/client.h
--- a/src/lmtp/client.h	Wed Nov 12 01:06:02 2014 +0200
+++ b/src/lmtp/client.h	Wed Nov 12 01:26:04 2014 +0200
@@ -79,8 +79,8 @@
 void client_disconnect(struct client *client, const char *prefix,
 		       const char *reason);
 void client_io_reset(struct client *client);
-void client_state_reset(struct client *client);
-void client_state_set(struct client *client, const char *name);
+void client_state_reset(struct client *client, const char *state_name);
+void client_state_set(struct client *client, const char *name, const char *args);
 const char *client_remote_id(struct client *client);
 
 void client_input_handle(struct client *client);
diff -r a4fbe94952ea -r aca0b7142046 src/lmtp/commands.c
--- a/src/lmtp/commands.c	Wed Nov 12 01:06:02 2014 +0200
+++ b/src/lmtp/commands.c	Wed Nov 12 01:26:04 2014 +0200
@@ -70,7 +70,7 @@
 		str_append(domain, "invalid");
 	}
 
-	client_state_reset(client);
+	client_state_reset(client, "LHLO");
 	client_send_line(client, "250-%s", client->my_domain);
 	if (master_service_ssl_is_enabled(master_service) &&
 	    client->ssl_iostream == NULL)
@@ -83,7 +83,7 @@
 
 	i_free(client->lhlo);
 	client->lhlo = i_strdup(str_c(domain));
-	client_state_set(client, "LHLO");
+	client_state_set(client, "LHLO", "");
 	return 0;
 }
 
@@ -180,7 +180,7 @@
 	client->state.mail_from = p_strdup(client->state_pool, addr);
 	p_array_init(&client->state.rcpt_to, client->state_pool, 64);
 	client_send_line(client, "250 2.1.0 OK");
-	client_state_set(client, "MAIL FROM");
+	client_state_set(client, "MAIL FROM", client->state.mail_from);
 	return 0;
 }
 
@@ -541,8 +541,6 @@
 	const char *error = NULL;
 	int ret = 0;
 
-	client_state_set(client, "RCPT TO");
-
 	if (client->state.mail_from == NULL) {
 		client_send_line(client, "503 5.5.1 MAIL needed first");
 		return 0;
@@ -563,6 +561,8 @@
 	}
 	rcpt_address_parse(client, address, &username, &detail);
 
+	client_state_set(client, "RCPT TO", address);
+
 	if (client->lmtp_set->lmtp_proxy) {
 		if (client_proxy_rcpt(client, address, username, detail))
 			return 0;
@@ -636,7 +636,7 @@
 
 int cmd_rset(struct client *client, const char *args ATTR_UNUSED)
 {
-	client_state_reset(client);
+	client_state_reset(client, "RSET");
 	client_send_line(client, "250 2.0.0 OK");
 	return 0;
 }
@@ -683,6 +683,7 @@
 			i_unreached();
 	}
 
+	client_state_set(client, "DATA", username);
 	i_set_failure_prefix("lmtp(%s, %s): ", my_pid, username);
 	if (mail_storage_service_next(storage_service, rcpt->service_user,
 				      &client->state.dest_user) < 0) {
@@ -772,6 +773,7 @@
 	while (client->state.rcpt_idx < count) {
 		ret = client_deliver(client, &rcpts[client->state.rcpt_idx],
 				     src_mail, session);
+		client_state_set(client, "DATA", "");
 		i_set_failure_prefix("lmtp(%s): ", my_pid);
 
 		client->state.rcpt_idx++;
@@ -917,7 +919,7 @@
 static void client_input_data_finish(struct client *client)
 {
 	client_io_reset(client);
-	client_state_reset(client);
+	client_state_reset(client, "DATA finished");
 	if (i_stream_have_bytes_left(client->input))
 		client_input_handle(client);
 }
@@ -979,6 +981,7 @@
 	if (array_count(&client->state.rcpt_to) != 0)
 		client_input_data_write_local(client, input);
 	if (client->proxy != NULL) {
+		client_state_set(client, "DATA", "proxying");
 		lmtp_proxy_start(client->proxy, input,
 				 client_proxy_finish, client);
 		ret = FALSE;
@@ -1107,7 +1110,7 @@
 	o_stream_uncork(client->output);
 
 	io_remove(&client->io);
-	client_state_set(client, "DATA");
+	client_state_set(client, "DATA", "");
 	client->io = io_add(client->fd_in, IO_READ, client_input_data, client);
 	client_input_data_handle(client);
 	return -1;
@@ -1147,7 +1150,7 @@
 	}
 
 	/* args ok, set them and reset the state */
-	client_state_reset(client);
+	client_state_reset(client, "XCLIENT");
 	if (remote_ip.family != 0)
 		client->remote_ip = remote_ip;
 	if (remote_port != 0)


More information about the dovecot-cvs mailing list