dovecot-2.0-sslstream: doveconf: Log a warning if Dovecot was la...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:57:31 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/26b5209dc4f4
changeset: 10573:26b5209dc4f4
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Jan 23 12:37:35 2010 +0200
description:
doveconf: Log a warning if Dovecot was last started using a different config file.

diffstat:

2 files changed, 43 insertions(+), 6 deletions(-)
src/config/doveconf.c |   30 ++++++++++++++++++++++++++----
src/master/main.c     |   19 +++++++++++++++++--

diffs (130 lines):

diff -r 749e7f1df078 -r 26b5209dc4f4 src/config/doveconf.c
--- a/src/config/doveconf.c	Sat Jan 23 12:37:14 2010 +0200
+++ b/src/config/doveconf.c	Sat Jan 23 12:37:35 2010 +0200
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "abspath.h"
 #include "env-util.h"
 #include "ostream.h"
 #include "str.h"
@@ -252,9 +253,9 @@ static int config_connection_request_hum
 	return ret;
 }
 
-static int config_dump_human(const struct config_filter *filter,
-			     const char *module,
-			     enum config_dump_scope scope)
+static int
+config_dump_human(const struct config_filter *filter, const char *module,
+		  enum config_dump_scope scope)
 {
 	struct ostream *output;
 	int ret;
@@ -321,19 +322,35 @@ static void filter_parse_arg(struct conf
 	}
 }
 
+static void check_wrong_config(const char *config_path)
+{
+	const char *prev_path;
+
+	if (t_readlink(PKG_RUNDIR"/"PACKAGE".conf", &prev_path) < 0)
+		return;
+
+	if (strcmp(prev_path, config_path) != 0) {
+		i_warning("Dovecot was last started using %s, "
+			  "but this config is %s", prev_path, config_path);
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	enum config_dump_scope scope = CONFIG_DUMP_SCOPE_ALL;
-	const char *config_path, *module = "";
+	const char *orig_config_path, *config_path, *module = "";
 	struct config_filter filter;
 	const char *error;
 	char **exec_args = NULL;
 	int c, ret, ret2;
+	bool config_path_specified;
 
 	memset(&filter, 0, sizeof(filter));
 	master_service = master_service_init("config",
 					     MASTER_SERVICE_FLAG_STANDALONE,
 					     &argc, &argv, "af:m:nNe");
+	orig_config_path = master_service_get_config_path(master_service);
+
 	i_set_failure_prefix("doveconf: ");
 	while ((c = master_getopt(master_service)) > 0) {
 		if (c == 'e')
@@ -358,6 +375,9 @@ int main(int argc, char *argv[])
 		}
 	}
 	config_path = master_service_get_config_path(master_service);
+	/* use strcmp() instead of !=, because dovecot -n always gives us
+	   -c parameter */
+	config_path_specified = strcmp(config_path, orig_config_path) != 0;
 
 	if (argv[optind] != NULL) {
 		if (c != 'e')
@@ -387,6 +407,8 @@ int main(int argc, char *argv[])
 		info = sysinfo_get(get_mail_location());
 		if (*info != '\0')
 			printf("# %s\n", info);
+		if (!config_path_specified)
+			check_wrong_config(config_path);
 		fflush(stdout);
 		ret2 = config_dump_human(&filter, module, scope);
 
diff -r 749e7f1df078 -r 26b5209dc4f4 src/master/main.c
--- a/src/master/main.c	Sat Jan 23 12:37:14 2010 +0200
+++ b/src/master/main.c	Sat Jan 23 12:37:35 2010 +0200
@@ -276,6 +276,20 @@ static void create_pid_file(const char *
 	(void)close(fd);
 }
 
+static void create_config_symlink(const struct master_settings *set)
+{
+	const char *base_config_path;
+
+	base_config_path = t_strconcat(set->base_dir, "/"PACKAGE".conf", NULL);
+	if (unlink(base_config_path) < 0 && errno != ENOENT)
+		i_error("unlink(%s) failed: %m", base_config_path);
+
+	if (symlink(services->config->config_file_path, base_config_path) < 0) {
+		i_error("symlink(%s, %s) failed: %m",
+			services->config->config_file_path, base_config_path);
+	}
+}
+
 static void
 sig_settings_reload(const siginfo_t *si ATTR_UNUSED,
 		    void *context ATTR_UNUSED)
@@ -378,7 +392,7 @@ static void main_log_startup(void)
 		i_info(STARTUP_STRING);
 }
 
-static void main_init(bool log_error)
+static void main_init(const struct master_settings *set, bool log_error)
 {
 	drop_capabilities();
 
@@ -405,6 +419,7 @@ static void main_init(bool log_error)
         lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
 
 	create_pid_file(pidfile_path);
+	create_config_symlink(set);
 
 	services_monitor_start(services);
 }
@@ -757,7 +772,7 @@ int main(int argc, char *argv[])
 	i_set_fatal_handler(master_fatal_callback);
 	i_set_error_handler(orig_error_callback);
 
-	main_init(log_error);
+	main_init(set, log_error);
 	master_service_run(master_service, NULL);
 	main_deinit();
 	master_service_deinit(&master_service);


More information about the dovecot-cvs mailing list