dovecot-2.0: doveadm: Output flushing fixes.

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 21 17:34:51 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/4e54843f11d0
changeset: 11591:4e54843f11d0
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 21 15:34:48 2010 +0100
description:
doveadm: Output flushing fixes.

diffstat:

 src/doveadm/doveadm-mail.c          |   1 +
 src/doveadm/doveadm-print-flow.c    |  14 ++++++++++----
 src/doveadm/doveadm-print-private.h |   1 +
 src/doveadm/doveadm-print-tab.c     |  11 +++++++----
 src/doveadm/doveadm-print-table.c   |  14 ++++++++++----
 src/doveadm/doveadm-print.c         |  11 +++++++++++
 src/doveadm/doveadm-print.h         |   1 +
 7 files changed, 41 insertions(+), 12 deletions(-)

diffs (170 lines):

diff -r 542d859f0223 -r 4e54843f11d0 src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Mon Jun 21 15:26:00 2010 +0100
+++ b/src/doveadm/doveadm-mail.c	Mon Jun 21 15:34:48 2010 +0100
@@ -397,6 +397,7 @@
 		doveadm_mail_all_users(ctx, wildcard_user, service_flags);
 	}
 	ctx->v.deinit(ctx);
+	doveadm_print_flush();
 
 	if (ctx->failed)
 		exit(FATAL_DEFAULT);
diff -r 542d859f0223 -r 4e54843f11d0 src/doveadm/doveadm-print-flow.c
--- a/src/doveadm/doveadm-print-flow.c	Mon Jun 21 15:26:00 2010 +0100
+++ b/src/doveadm/doveadm-print-flow.c	Mon Jun 21 15:34:48 2010 +0100
@@ -56,11 +56,16 @@
 	p_array_init(&ctx->headers, pool, 16);
 }
 
+static void doveadm_print_flow_flush(void)
+{
+	if (ctx->header_idx != 0) {
+		printf("\n");
+		ctx->header_idx = 0;
+	}
+}
+
 static void doveadm_print_flow_deinit(void)
 {
-	if (ctx->header_idx != 0)
-		printf("\n");
-
 	pool_unref(&ctx->pool);
 	ctx = NULL;
 }
@@ -71,5 +76,6 @@
 	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 -r 542d859f0223 -r 4e54843f11d0 src/doveadm/doveadm-print-private.h
--- a/src/doveadm/doveadm-print-private.h	Mon Jun 21 15:26:00 2010 +0100
+++ b/src/doveadm/doveadm-print-private.h	Mon Jun 21 15:34:48 2010 +0100
@@ -17,6 +17,7 @@
 
 	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 -r 542d859f0223 -r 4e54843f11d0 src/doveadm/doveadm-print-tab.c
--- a/src/doveadm/doveadm-print-tab.c	Mon Jun 21 15:26:00 2010 +0100
+++ b/src/doveadm/doveadm-print-tab.c	Mon Jun 21 15:34:48 2010 +0100
@@ -40,17 +40,20 @@
 	}
 }
 
-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 -r 542d859f0223 -r 4e54843f11d0 src/doveadm/doveadm-print-table.c
--- a/src/doveadm/doveadm-print-table.c	Mon Jun 21 15:26:00 2010 +0100
+++ b/src/doveadm/doveadm-print-table.c	Mon Jun 21 15:34:48 2010 +0100
@@ -51,6 +51,8 @@
 	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 @@
 	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_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 @@
 	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 -r 542d859f0223 -r 4e54843f11d0 src/doveadm/doveadm-print.c
--- a/src/doveadm/doveadm-print.c	Mon Jun 21 15:26:00 2010 +0100
+++ b/src/doveadm/doveadm-print.c	Mon Jun 21 15:34:48 2010 +0100
@@ -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 @@
 	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 @@
 	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 -r 542d859f0223 -r 4e54843f11d0 src/doveadm/doveadm-print.h
--- a/src/doveadm/doveadm-print.h	Mon Jun 21 15:26:00 2010 +0100
+++ b/src/doveadm/doveadm-print.h	Mon Jun 21 15:34:48 2010 +0100
@@ -18,6 +18,7 @@
 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);


More information about the dovecot-cvs mailing list