dovecot-2.0: imap: If client disconnects in APPEND, log more abo...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 16 17:03:04 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/53fed82f8013
changeset: 12809:53fed82f8013
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 16 17:02:56 2011 +0300
description:
imap: If client disconnects in APPEND, log more about what it did before that.

diffstat:

 src/imap/cmd-append.c |  21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diffs (60 lines):

diff -r d9d5759196ee -r 53fed82f8013 src/imap/cmd-append.c
--- a/src/imap/cmd-append.c	Mon May 16 15:53:13 2011 +0300
+++ b/src/imap/cmd-append.c	Mon May 16 17:02:56 2011 +0300
@@ -24,6 +24,7 @@
 	struct mail_storage *storage;
 	struct mailbox *box;
         struct mailbox_transaction_context *t;
+	time_t started;
 
 	struct istream *input;
 	uoff_t msg_size;
@@ -40,10 +41,26 @@
 static bool cmd_append_continue_message(struct client_command_context *cmd);
 static bool cmd_append_continue_parsing(struct client_command_context *cmd);
 
+static const char *get_disconnect_reason(struct cmd_append_context *ctx)
+{
+	string_t *str = t_str_new(128);
+	unsigned int secs = ioloop_time - ctx->started;
+
+	str_printfa(str, "Disconnected in APPEND (%u msgs, %u secs",
+		    ctx->count, secs);
+	if (ctx->input != NULL) {
+		str_printfa(str, ", %"PRIuUOFF_T"/%"PRIuUOFF_T" bytes",
+			    ctx->input->v_offset, ctx->msg_size);
+	}
+	str_append_c(str, ')');
+	return str_c(str);
+}
+
 static void client_input_append(struct client_command_context *cmd)
 {
 	struct cmd_append_context *ctx = cmd->context;
 	struct client *client = cmd->client;
+	const char *reason;
 	bool finished;
 
 	i_assert(!client->destroyed);
@@ -54,11 +71,12 @@
 	switch (i_stream_read(client->input)) {
 	case -1:
 		/* disconnected */
+		reason = get_disconnect_reason(ctx);
 		cmd_append_finish(cmd->context);
 		/* Reset command so that client_destroy() doesn't try to call
 		   cmd_append_continue_message() anymore. */
 		client_command_free(&cmd);
-		client_destroy(client, "Disconnected in APPEND");
+		client_destroy(client, reason);
 		return;
 	case -2:
 		if (ctx->message_input) {
@@ -510,6 +528,7 @@
 	ctx->cmd = cmd;
 	ctx->client = client;
 	ctx->box = get_mailbox(cmd, mailbox);
+	ctx->started = ioloop_time;
 	if (ctx->box == NULL)
 		ctx->failed = TRUE;
 	else {


More information about the dovecot-cvs mailing list