dovecot-2.0: doveadm: stop and reload commands now run with mini...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 7 19:48:54 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/c73ddaa39ca4
changeset: 11489:c73ddaa39ca4
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 07 17:48:51 2010 +0100
description:
doveadm: stop and reload commands now run with minimal initialization code.
This allows them to work even if there is something wrong with config file.

diffstat:

 src/doveadm/doveadm.c |  33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)

diffs (66 lines):

diff -r 4b20e692c606 -r c73ddaa39ca4 src/doveadm/doveadm.c
--- a/src/doveadm/doveadm.c	Mon Jun 07 17:06:17 2010 +0100
+++ b/src/doveadm/doveadm.c	Mon Jun 07 17:48:51 2010 +0100
@@ -291,6 +291,7 @@
 	struct master_service_settings_output output;
 	const char *cmd_name, *error;
 	unsigned int i;
+	bool quick_init;
 	int c;
 
 	/* "+" is GNU extension to stop at the first non-option.
@@ -310,6 +311,7 @@
 			return FATAL_DEFAULT;
 		}
 	}
+	cmd_name = argv[optind];
 
 	memset(&input, 0, sizeof(input));
 	input.roots = set_roots;
@@ -323,15 +325,26 @@
 	i_array_init(&doveadm_cmds, 32);
 	for (i = 0; i < N_ELEMENTS(doveadm_commands); i++)
 		doveadm_register_cmd(doveadm_commands[i]);
-	doveadm_register_director_commands();
-	doveadm_register_log_commands();
-	doveadm_mail_init();
-	doveadm_load_modules();
 
-	if (optind == argc)
-		usage_to(stdout, "");
+	if (cmd_name != NULL && (strcmp(cmd_name, "stop") == 0 ||
+				 strcmp(cmd_name, "reload") == 0)) {
+		/* special case commands: even if there is something wrong
+		   with the config (e.g. mail_plugins), don't fail these
+		   commands */
+		quick_init = TRUE;
+	} else {
+		quick_init = FALSE;
+		doveadm_register_director_commands();
+		doveadm_register_log_commands();
+		doveadm_mail_init();
+		doveadm_load_modules();
 
-	cmd_name = argv[optind];
+		if (cmd_name == NULL) {
+			/* show usage after registering all plugins */
+			usage_to(stdout, "");
+		}
+	}
+
 	argc -= optind;
 	argv += optind;
 	optind = 1;
@@ -349,8 +362,10 @@
 		usage();
 	}
 
-	doveadm_mail_deinit();
-	module_dir_unload(&modules);
+	if (!quick_init) {
+		doveadm_mail_deinit();
+		module_dir_unload(&modules);
+	}
 	array_free(&doveadm_cmds);
 	master_service_deinit(&master_service);
 	return 0;


More information about the dovecot-cvs mailing list