From: Timo Sirainen Date: Wed, 23 Oct 2013 11:34:35 +0000 (+0300) Subject: doveadm-server: Don't call io_loop_run() recursively for the same ioloop. X-Git-Tag: 2.2.7~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=06c303e21a11e11209f40a2658f2864819d59f70;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/doveadm/client-connection.c b/src/doveadm/client-connection.c index 1008a5f109..fce598bf9b 100644 --- a/src/doveadm/client-connection.c +++ b/src/doveadm/client-connection.c @@ -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 @@ doveadm_mail_cmd_server_run(struct client_connection *conn, 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_mail_cmd_server_run(struct client_connection *conn, 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 @@ static bool client_handle_command(struct client_connection *conn, char **args) 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 @@ static bool client_handle_command(struct client_connection *conn, char **args) 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 --git a/src/doveadm/doveadm-mail-server.c b/src/doveadm/doveadm-mail-server.c index 99c1894bb7..cdadc1f4b4 100644 --- a/src/doveadm/doveadm-mail-server.c +++ b/src/doveadm/doveadm-mail-server.c @@ -164,7 +164,7 @@ static void doveadm_server_flush_one(struct doveadm_server *server) 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());