dovecot-2.2: dsync: Set doveadm exit codes properly on errors.

dovecot at dovecot.org dovecot at dovecot.org
Sat Dec 15 13:55:47 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/79bcf862bf1c
changeset: 15480:79bcf862bf1c
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Dec 15 13:55:33 2012 +0200
description:
dsync: Set doveadm exit codes properly on errors.

diffstat:

 src/doveadm/dsync/doveadm-dsync.c |  35 +++++++++++++++++++++++++++--------
 1 files changed, 27 insertions(+), 8 deletions(-)

diffs (87 lines):

diff -r 984a5b4fa793 -r 79bcf862bf1c src/doveadm/dsync/doveadm-dsync.c
--- a/src/doveadm/dsync/doveadm-dsync.c	Sat Dec 15 13:48:22 2012 +0200
+++ b/src/doveadm/dsync/doveadm-dsync.c	Sat Dec 15 13:55:33 2012 +0200
@@ -244,6 +244,7 @@
 	struct setting_parser_context *set_parser;
 	const char *set_line, *path1, *path2;
 	bool brain1_running, brain2_running, changed1, changed2;
+	int ret;
 
 	i_assert(ctx->local_location != NULL);
 
@@ -255,16 +256,23 @@
 	set_line = t_strconcat("mail_location=", ctx->local_location, NULL);
 	if (settings_parse_line(set_parser, set_line) < 0)
 		i_unreached();
-	if (mail_storage_service_next(ctx->ctx.storage_service,
-				      ctx->ctx.cur_service_user, &user2) < 0)
-		i_fatal("User init failed");
+	ret = mail_storage_service_next(ctx->ctx.storage_service,
+					ctx->ctx.cur_service_user, &user2);
+	if (ret < 0) {
+		ctx->ctx.exit_code = ret == -1 ? EX_TEMPFAIL : EX_CONFIG;
+		mail_user_unref(&user2);
+		return -1;
+	}
 	user2->admin = TRUE;
 
 	if (mail_namespaces_get_root_sep(user->namespaces) !=
 	    mail_namespaces_get_root_sep(user2->namespaces)) {
-		i_fatal("Mail locations must use the same "
+		i_error("Mail locations must use the same "
 			"virtual mailbox hierarchy separator "
 			"(specify separator for the default namespace)");
+		ctx->ctx.exit_code = EX_CONFIG;
+		mail_user_unref(&user2);
+		return -1;
 	}
 	if (mailbox_list_get_root_path(user->namespaces->list,
 				       MAILBOX_LIST_PATH_TYPE_MAILBOX,
@@ -273,8 +281,11 @@
 				       MAILBOX_LIST_PATH_TYPE_MAILBOX,
 				       &path2) &&
 	    strcmp(path1, path2) == 0) {
-		i_fatal("Both source and destination mail_location "
+		i_error("Both source and destination mail_location "
 			"points to same directory: %s", path1);
+		ctx->ctx.exit_code = EX_CONFIG;
+		mail_user_unref(&user2);
+		return -1;
 	}
 
 	brain2 = dsync_brain_slave_init(user2, ibc2);
@@ -291,7 +302,11 @@
 		brain2_running = dsync_brain_run(brain2, &changed2);
 	}
 	mail_user_unref(&user2);
-	return dsync_brain_deinit(&brain2);
+	if (dsync_brain_deinit(&brain2) < 0) {
+		ctx->ctx.exit_code = EX_TEMPFAIL;
+		return -1;
+	}
+	return 0;
 }
 
 static void
@@ -380,7 +395,7 @@
 
 	if (!ctx->remote) {
 		if (cmd_dsync_run_local(ctx, user, brain, ibc2) < 0)
-			_ctx->exit_code = EX_TEMPFAIL;
+			ret = -1;
 	} else {
 		cmd_dsync_run_remote(user);
 	}
@@ -584,7 +599,11 @@
 	io_loop_run(current_ioloop);
 
 	dsync_ibc_deinit(&ibc);
-	return dsync_brain_deinit(&brain);
+	if (dsync_brain_deinit(&brain) < 0) {
+		_ctx->exit_code = EX_TEMPFAIL;
+		return -1;
+	}
+	return 0;
 }
 
 static bool


More information about the dovecot-cvs mailing list