]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm-server: Don't call io_loop_run() recursively for the same ioloop.
authorTimo Sirainen <tss@iki.fi>
Wed, 23 Oct 2013 11:34:35 +0000 (14:34 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 23 Oct 2013 11:34:35 +0000 (14:34 +0300)
This breaks things more or less badly, especially ioloop-kqueue really
didn't like it.

src/doveadm/client-connection.c
src/doveadm/doveadm-mail-server.c

index 1008a5f1095f3f2a2dee610ba4f8a7874f4a19b1..fce598bf9b17354d2a73fcd81fdf3a25a98702aa 100644 (file)
@@ -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;
 }
 
index 99c1894bb7d842d1289d036cf9f9218bf546fe9d..cdadc1f4b47c6446a7ebc96c21ed99c302f92a2a 100644 (file)
@@ -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());