Mercurial > dovecot > core-2.2
changeset 10572:26b5209dc4f4 HEAD
doveconf: Log a warning if Dovecot was last started using a different config file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 23 Jan 2010 12:37:35 +0200 |
parents | 749e7f1df078 |
children | 823356f533c5 |
files | src/config/doveconf.c src/master/main.c |
diffstat | 2 files changed, 43 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ 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 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 @@ } } 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 @@ 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);
--- 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 @@ (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 @@ 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 @@ 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 @@ 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);