dovecot-2.2: doveadm-server: Don't call io_loop_run() recursivel...

dovecot at dovecot.org dovecot at dovecot.org
Wed Oct 23 14:34:46 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/d06acaf2c640
changeset: 16867:d06acaf2c640
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Oct 23 14:34:35 2013 +0300
description:
doveadm-server: Don't call io_loop_run() recursively for the same ioloop.
This breaks things more or less badly, especially ioloop-kqueue really
didn't like it.

diffstat:

 src/doveadm/client-connection.c   |  18 ++++++++++++------
 src/doveadm/doveadm-mail-server.c |   2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)

diffs (72 lines):

diff -r 100a2c0ce5e8 -r d06acaf2c640 src/doveadm/client-connection.c
--- a/src/doveadm/client-connection.c	Wed Oct 23 11:47:10 2013 +0300
+++ b/src/doveadm/client-connection.c	Wed Oct 23 14:34:35 2013 +0300
@@ -1,6 +1,7 @@
 /* Copyright (c) 2010-2013 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "lib-signals.h"
 #include "base64.h"
 #include "ioloop.h"
 #include "istream.h"
@@ -107,10 +108,16 @@
 			    const struct mail_storage_service_input *input)
 {
 	const char *error;
+	struct ioloop *ioloop, *prev_ioloop = current_ioloop;
 	int ret;
 
 	ctx->conn = conn;
 
+	/* some commands will want to call io_loop_run(), but we're already
+	   running one and we can't call the original one recursively, so
+	   create a new ioloop. */
+	ioloop = io_loop_create();
+	lib_signals_reset_ioloop();
 	if (ctx->v.preinit != NULL)
 		ctx->v.preinit(ctx);
 
@@ -120,6 +127,11 @@
 	doveadm_print_flush();
 	mail_storage_service_deinit(&ctx->storage_service);
 
+	current_ioloop = prev_ioloop;
+	lib_signals_reset_ioloop();
+	current_ioloop = ioloop;
+	io_loop_destroy(&ioloop);
+
 	if (ret < 0) {
 		i_error("%s: %s", ctx->cmd->name, error);
 		o_stream_nsend(conn->output, "\n-\n", 3);
@@ -212,10 +224,6 @@
 		return FALSE;
 	}
 
-	/* make sure client_connection_input() isn't called by the ioloop that
-	   is going to be run by doveadm_mail_cmd_server_run() */
-	io_remove(&conn->io);
-
 	o_stream_cork(conn->output);
 	ctx = doveadm_mail_cmd_server_parse(cmd_name, conn->set, &input, argc, args);
 	if (ctx == NULL)
@@ -228,8 +236,6 @@
 	net_set_nonblock(conn->fd, FALSE);
 	(void)o_stream_flush(conn->output);
 	net_set_nonblock(conn->fd, TRUE);
-
-	conn->io = io_add(conn->fd, IO_READ, client_connection_input, conn);
 	return TRUE;
 }
 
diff -r 100a2c0ce5e8 -r d06acaf2c640 src/doveadm/doveadm-mail-server.c
--- a/src/doveadm/doveadm-mail-server.c	Wed Oct 23 11:47:10 2013 +0300
+++ b/src/doveadm/doveadm-mail-server.c	Wed Oct 23 14:34:35 2013 +0300
@@ -164,7 +164,7 @@
 	unsigned int count = array_count(&server->queue);
 
 	do {
-		master_service_run(master_service, NULL);
+		io_loop_run(current_ioloop);
 	} while (array_count(&server->queue) == count &&
 		 doveadm_server_have_used_connections(server) &&
 		 !DOVEADM_MAIL_SERVER_FAILED());


More information about the dovecot-cvs mailing list