From: Timo Sirainen Date: Mon, 21 Jun 2010 14:34:48 +0000 (+0100) Subject: doveadm: Output flushing fixes. X-Git-Tag: 2.0.rc1~127 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09304bdc1e5e416aa343802732a15064f49495cc;p=thirdparty%2Fdovecot%2Fcore.git doveadm: Output flushing fixes. --HG-- branch : HEAD --- diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index 9f25557525..49e7a4e16c 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -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); diff --git a/src/doveadm/doveadm-print-flow.c b/src/doveadm/doveadm-print-flow.c index d372a4fa58..fb24a15955 100644 --- a/src/doveadm/doveadm-print-flow.c +++ b/src/doveadm/doveadm-print-flow.c @@ -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 }; diff --git a/src/doveadm/doveadm-print-private.h b/src/doveadm/doveadm-print-private.h index 5ff4d8b1b9..17c8ae8f72 100644 --- a/src/doveadm/doveadm-print-private.h +++ b/src/doveadm/doveadm-print-private.h @@ -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; diff --git a/src/doveadm/doveadm-print-tab.c b/src/doveadm/doveadm-print-tab.c index ffe5e68c94..35ececa2e0 100644 --- a/src/doveadm/doveadm-print-tab.c +++ b/src/doveadm/doveadm-print-tab.c @@ -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 }; diff --git a/src/doveadm/doveadm-print-table.c b/src/doveadm/doveadm-print-table.c index 8ef6a65421..3fb972a09b 100644 --- a/src/doveadm/doveadm-print-table.c +++ b/src/doveadm/doveadm-print-table.c @@ -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 }; diff --git a/src/doveadm/doveadm-print.c b/src/doveadm/doveadm-print.c index 47a0ec830f..ad6e8d39ac 100644 --- a/src/doveadm/doveadm-print.c +++ b/src/doveadm/doveadm-print.c @@ -4,6 +4,8 @@ #include "array.h" #include "doveadm-print-private.h" +#include + 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); diff --git a/src/doveadm/doveadm-print.h b/src/doveadm/doveadm-print.h index 71e4db0b9d..33e8a13c1a 100644 --- a/src/doveadm/doveadm-print.h +++ b/src/doveadm/doveadm-print.h @@ -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);