]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Output flushing fixes.
authorTimo Sirainen <tss@iki.fi>
Mon, 21 Jun 2010 14:34:48 +0000 (15:34 +0100)
committerTimo Sirainen <tss@iki.fi>
Mon, 21 Jun 2010 14:34:48 +0000 (15:34 +0100)
--HG--
branch : HEAD

src/doveadm/doveadm-mail.c
src/doveadm/doveadm-print-flow.c
src/doveadm/doveadm-print-private.h
src/doveadm/doveadm-print-tab.c
src/doveadm/doveadm-print-table.c
src/doveadm/doveadm-print.c
src/doveadm/doveadm-print.h

index 9f25557525ab714ef3961f93f71bdfaeaab9dccb..49e7a4e16c0bfe55425051d60174d48abd32b30c 100644 (file)
@@ -397,6 +397,7 @@ doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[])
                doveadm_mail_all_users(ctx, wildcard_user, service_flags);
        }
        ctx->v.deinit(ctx);
+       doveadm_print_flush();
 
        if (ctx->failed)
                exit(FATAL_DEFAULT);
index d372a4fa58fa4f04bd34175d1adf5b6bcb844f2c..fb24a159553200af1c77649591c2d26d33cacf54 100644 (file)
@@ -56,11 +56,16 @@ static void doveadm_print_flow_init(void)
        p_array_init(&ctx->headers, pool, 16);
 }
 
-static void doveadm_print_flow_deinit(void)
+static void doveadm_print_flow_flush(void)
 {
-       if (ctx->header_idx != 0)
+       if (ctx->header_idx != 0) {
                printf("\n");
+               ctx->header_idx = 0;
+       }
+}
 
+static void doveadm_print_flow_deinit(void)
+{
        pool_unref(&ctx->pool);
        ctx = NULL;
 }
@@ -71,5 +76,6 @@ struct doveadm_print_vfuncs doveadm_print_flow_vfuncs = {
        doveadm_print_flow_init,
        doveadm_print_flow_deinit,
        doveadm_print_flow_header,
-       doveadm_print_flow_print
+       doveadm_print_flow_print,
+       doveadm_print_flow_flush
 };
index 5ff4d8b1b9e7817bf032e354b4f57b34e3508a18..17c8ae8f72ac07d35a91dae55ad9b5a7674a0dad 100644 (file)
@@ -17,6 +17,7 @@ struct doveadm_print_vfuncs {
 
        void (*header)(const struct doveadm_print_header *hdr);
        void (*print)(const char *value);
+       void (*flush)(void);
 };
 
 extern struct doveadm_print_vfuncs doveadm_print_flow_vfuncs;
index ffe5e68c9435a1923a0b3c50f18f220a4ac8a7a3..35ececa2e04ec7bbd79821aff767809cda2fef57 100644 (file)
@@ -40,17 +40,20 @@ static void doveadm_print_tab_print(const char *value)
        }
 }
 
-static void doveadm_print_tab_deinit(void)
+static void doveadm_print_tab_flush(void)
 {
-       if (!ctx.header_written)
+       if (!ctx.header_written) {
                printf("\n");
+               ctx.header_written = TRUE;
+       }
 }
 
 struct doveadm_print_vfuncs doveadm_print_tab_vfuncs = {
        "tab",
 
        NULL,
-       doveadm_print_tab_deinit,
+       NULL,
        doveadm_print_tab_header,
-       doveadm_print_tab_print
+       doveadm_print_tab_print,
+       doveadm_print_tab_flush
 };
index 8ef6a65421d7f85d518f60e063ab46cdea17abf7..3fb972a09b8d4dbbe39b8807799e7f7089c921a1 100644 (file)
@@ -51,6 +51,8 @@ static void doveadm_calc_header_length(void)
        unsigned int i, line, len, hdr_count, value_count, line_count;
        unsigned int max_length, orig_length, diff;
 
+       ctx->lengths_set = TRUE;
+
        headers = array_get_modifiable(&ctx->headers, &hdr_count);
        values = array_get(&ctx->buffered_values, &value_count);
        i_assert((value_count % hdr_count) == 0);
@@ -169,6 +171,12 @@ static void doveadm_print_table_print(const char *value)
        doveadm_print_next(value);
 }
 
+static void doveadm_print_table_flush(void)
+{
+       if (!ctx->lengths_set && array_count(&ctx->headers) > 0)
+               doveadm_buffer_flush();
+}
+
 static void doveadm_print_table_init(void)
 {
        pool_t pool;
@@ -189,9 +197,6 @@ static void doveadm_print_table_init(void)
 
 static void doveadm_print_table_deinit(void)
 {
-       if (!ctx->lengths_set && array_count(&ctx->headers) > 0)
-               doveadm_buffer_flush();
-
        array_free(&ctx->buffered_values);
        pool_unref(&ctx->pool);
        ctx = NULL;
@@ -203,5 +208,6 @@ struct doveadm_print_vfuncs doveadm_print_table_vfuncs = {
        doveadm_print_table_init,
        doveadm_print_table_deinit,
        doveadm_print_table_header,
-       doveadm_print_table_print
+       doveadm_print_table_print,
+       doveadm_print_table_flush
 };
index 47a0ec830f03557c8543987fe37405314e6dea12..ad6e8d39aca1e33a95cb5aabaaffd8711ea87a93 100644 (file)
@@ -4,6 +4,8 @@
 #include "array.h"
 #include "doveadm-print-private.h"
 
+#include <stdio.h>
+
 struct doveadm_print_header_context {
        const char *key;
        char *sticky_value;
@@ -102,6 +104,13 @@ void doveadm_print_sticky(const char *key, const char *value)
        i_unreached();
 }
 
+void doveadm_print_flush(void)
+{
+       if (ctx != NULL && ctx->v->flush != NULL)
+               ctx->v->flush();
+       fflush(stdout);
+}
+
 void doveadm_print_init(const char *name)
 {
        pool_t pool;
@@ -136,6 +145,8 @@ void doveadm_print_deinit(void)
        if (ctx == NULL)
                return;
 
+       if (ctx->v->flush != NULL)
+               ctx->v->flush();
        ctx->v->deinit();
        array_foreach_modifiable(&ctx->headers, hdr)
                i_free(hdr->sticky_value);
index 71e4db0b9da6f9e1a7180855be0ededd9dff73f9..33e8a13c1a4bf2a7589922c1612b9228bf46f64c 100644 (file)
@@ -18,6 +18,7 @@ void doveadm_print_header_simple(const char *key_title);
 void doveadm_print(const char *value);
 void doveadm_print_num(uintmax_t value);
 void doveadm_print_sticky(const char *key, const char *value);
+void doveadm_print_flush(void);
 
 void doveadm_print_init(const char *name);
 void doveadm_print_deinit(void);