dovecot-1.2: dovecot -a|-n: Log a warning if Dovecot was last st...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jan 22 18:59:01 EET 2010
details: http://hg.dovecot.org/dovecot-1.2/rev/142c935e44d6
changeset: 9528:142c935e44d6
user: Timo Sirainen <tss at iki.fi>
date: Fri Jan 22 18:58:51 2010 +0200
description:
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
diffstat:
3 files changed, 43 insertions(+), 6 deletions(-)
src/master/main.c | 17 ++++++++++++++---
src/master/master-settings.c | 29 +++++++++++++++++++++++++++--
src/master/master-settings.h | 3 ++-
diffs (135 lines):
diff -r 2a7efac89339 -r 142c935e44d6 src/master/main.c
--- a/src/master/main.c Fri Jan 22 17:06:57 2010 +0200
+++ b/src/master/main.c Fri Jan 22 18:58:51 2010 +0200
@@ -193,7 +193,7 @@ static void settings_reload(void)
/* see if hostname changed */
hostpid_init();
- if (!master_settings_read(configfile, FALSE, FALSE))
+ if (!master_settings_read(configfile, FALSE, FALSE, FALSE))
i_warning("Invalid configuration, keeping old one");
else {
if (!IS_INETD())
@@ -309,6 +309,8 @@ static void main_log_startup(void)
static void main_init(bool log_error)
{
+ const char *base_config_path;
+
drop_capabilities();
/* deny file access from everyone else except owner */
@@ -348,6 +350,13 @@ static void main_init(bool log_error)
create_pid_file(t_strconcat(settings_root->defaults->base_dir,
"/master.pid", NULL));
+ base_config_path = t_strconcat(settings_root->defaults->base_dir,
+ "/"PACKAGE".conf", NULL);
+ (void)unlink(base_config_path);
+ if (symlink(configfile, base_config_path) < 0) {
+ i_error("symlink(%s, %s) failed: %m",
+ configfile, base_config_path);
+ }
}
static void main_deinit(void)
@@ -518,6 +527,7 @@ int main(int argc, char *argv[])
const char *exec_protocol = NULL, **exec_args = NULL, *user, *home;
bool foreground = FALSE, ask_key_pass = FALSE, log_error = FALSE;
bool dump_config = FALSE, dump_config_nondefaults = FALSE;
+ bool config_path_given = FALSE;
int i;
#ifdef DEBUG
@@ -538,6 +548,7 @@ int main(int argc, char *argv[])
i++;
if (i == argc) i_fatal("Missing config file argument");
configfile = argv[i];
+ config_path_given = TRUE;
} else if (strcmp(argv[i], "-n") == 0) {
dump_config_nondefaults = dump_config = TRUE;
} else if (strcmp(argv[i], "-p") == 0) {
@@ -579,7 +590,6 @@ int main(int argc, char *argv[])
}
if (dump_config) {
-
/* print the config file path before parsing it, so in case
of errors it's still shown */
printf("# "VERSION": %s\n", configfile);
@@ -589,7 +599,8 @@ int main(int argc, char *argv[])
T_BEGIN {
master_settings_init();
if (!master_settings_read(configfile, exec_protocol != NULL,
- dump_config || log_error))
+ dump_config || log_error,
+ !config_path_given))
i_fatal("Invalid configuration in %s", configfile);
} T_END;
diff -r 2a7efac89339 -r 142c935e44d6 src/master/master-settings.c
--- a/src/master/master-settings.c Fri Jan 22 17:06:57 2010 +0200
+++ b/src/master/master-settings.c Fri Jan 22 18:58:51 2010 +0200
@@ -1545,7 +1545,28 @@ settings_warn_needed_fds(struct server_s
#endif
}
-bool master_settings_read(const char *path, bool nochecks, bool nofixes)
+static void check_wrong_config(struct settings_parse_ctx *ctx, const char *path)
+{
+ const char *base_dir = PKG_RUNDIR;
+ char prev_path[PATH_MAX];
+ int ret;
+
+ if (ctx->root != NULL && ctx->root->defaults != NULL)
+ base_dir = ctx->root->defaults->base_dir;
+ ret = readlink(t_strconcat(base_dir, "/"PACKAGE".conf", NULL),
+ prev_path, sizeof(prev_path)-1);
+ if (ret < 0 || ret == sizeof(prev_path)-1)
+ return;
+ prev_path[ret] = '\0';
+
+ if (strcmp(prev_path, path) != 0) {
+ i_warning("Dovecot was last started using %s, "
+ "but this config is %s", prev_path, path);
+ }
+}
+
+bool master_settings_read(const char *path, bool nochecks, bool nofixes,
+ bool warn_wrong_config)
{
struct settings_parse_ctx ctx;
struct server_settings *server, *prev;
@@ -1553,6 +1574,7 @@ bool master_settings_read(const char *pa
struct auth_settings *auth;
struct namespace_settings *ns;
pool_t temp;
+ bool ret;
memset(&ctx, 0, sizeof(ctx));
@@ -1565,7 +1587,10 @@ bool master_settings_read(const char *pa
&default_settings, &default_settings);
ctx.auth = &ctx.server->auth_defaults;
- if (!settings_read(path, NULL, parse_setting, parse_section, &ctx))
+ ret = settings_read(path, NULL, parse_setting, parse_section, &ctx);
+ if (warn_wrong_config)
+ check_wrong_config(&ctx, path);
+ if (!ret)
return FALSE;
if (ctx.level != 0) {
diff -r 2a7efac89339 -r 142c935e44d6 src/master/master-settings.h
--- a/src/master/master-settings.h Fri Jan 22 17:06:57 2010 +0200
+++ b/src/master/master-settings.h Fri Jan 22 18:58:51 2010 +0200
@@ -268,7 +268,8 @@ struct server_settings {
extern struct server_settings *settings_root;
-bool master_settings_read(const char *path, bool nochecks, bool nofixes);
+bool master_settings_read(const char *path, bool nochecks, bool nofixes,
+ bool warn_wrong_config);
void master_settings_dump(struct server_settings *set, bool nondefaults);
More information about the dovecot-cvs
mailing list