# HG changeset patch # User Timo Sirainen # Date 1264179531 -7200 # Node ID 142c935e44d6928f5327aa408c03d2f2cf4e730d # Parent 2a7efac8933927a6fc022c93e4bfc7a3155360f3 dovecot -a|-n: Log a warning if Dovecot was last started using a different config file. 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 @@ /* 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_init(bool log_error) { + const char *base_config_path; + drop_capabilities(); /* deny file access from everyone else except owner */ @@ -348,6 +350,13 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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 @@ #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 @@ struct auth_settings *auth; struct namespace_settings *ns; pool_t temp; + bool ret; memset(&ctx, 0, sizeof(ctx)); @@ -1565,7 +1587,10 @@ &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 @@ 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);