dovecot-2.2: dsync: Make sure we print all the stderr output fro...

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 26 13:45:37 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/80efae622dc1
changeset: 19015:80efae622dc1
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 26 15:44:45 2015 +0200
description:
dsync: Make sure we print all the stderr output from remote processes at deinit.
Earlier the final messages may have been lost, especially if debug logging
was enabled.

diffstat:

 src/doveadm/doveadm-dsync.c |  30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diffs (62 lines):

diff -r 11b107c8dc05 -r 80efae622dc1 src/doveadm/doveadm-dsync.c
--- a/src/doveadm/doveadm-dsync.c	Wed Aug 26 15:19:27 2015 +0200
+++ b/src/doveadm/doveadm-dsync.c	Wed Aug 26 15:44:45 2015 +0200
@@ -118,6 +118,10 @@
 	case -1:
 		if (ctx->io_err != NULL)
 			io_remove(&ctx->io_err);
+		if (ctx->fd_in == -1) {
+			/* we're shutting down. */
+			io_loop_stop(current_ioloop);
+		}
 		break;
 	default:
 		while ((line = i_stream_next_line(ctx->err_stream)) != NULL)
@@ -406,9 +410,18 @@
 static void cmd_dsync_wait_remote(struct dsync_cmd_context *ctx,
 				  int *status_r)
 {
-	/* wait for the remote command to finish to see any final errors.
-	   don't wait very long though. */
-	alarm(DSYNC_REMOTE_CMD_EXIT_WAIT_SECS);
+	struct timeout *to;
+
+	/* wait for stderr to close. this indicates that the remote process
+	   has died. while we're running we're also reading and printing all
+	   errors that still coming from it. */
+	to = timeout_add(DSYNC_REMOTE_CMD_EXIT_WAIT_SECS*1000,
+			 io_loop_stop, current_ioloop);
+	io_loop_run(current_ioloop);
+	timeout_remove(&to);
+
+	/* unless we timed out, the process should be dead now or very soon. */
+	alarm(1);
 	if (waitpid(ctx->remote_pid, status_r, 0) == -1) {
 		if (errno != EINTR) {
 			i_error("waitpid(%ld) failed: %m",
@@ -664,21 +677,18 @@
 			i_close_fd(&ctx->fd_out);
 		i_close_fd(&ctx->fd_in);
 	}
-	if (ctx->run_type == DSYNC_RUN_TYPE_CMD)
-		cmd_dsync_wait_remote(ctx, &status);
-
 	/* print any final errors after the process has died. not closing
 	   stdin/stdout before wait() may cause the process to hang, but stderr
 	   shouldn't (at least with ssh) and we need stderr to be open to be
 	   able to print the final errors */
-	if (ctx->err_stream != NULL) {
-		remote_error_input(ctx);
+	if (ctx->run_type == DSYNC_RUN_TYPE_CMD) {
+		cmd_dsync_wait_remote(ctx, &status);
 		remote_errors_logged = ctx->err_stream->v_offset > 0;
 		i_stream_destroy(&ctx->err_stream);
-	}
-	if (ctx->run_type == DSYNC_RUN_TYPE_CMD) {
 		cmd_dsync_log_remote_status(status, remote_errors_logged,
 					    ctx->remote_cmd_args);
+	} else {
+		i_assert(ctx->err_stream == NULL);
 	}
 	if (ctx->io_err != NULL)
 		io_remove(&ctx->io_err);


More information about the dovecot-cvs mailing list