From: Timo Sirainen Date: Sat, 23 Jan 2010 10:37:35 +0000 (+0200) Subject: doveconf: Log a warning if Dovecot was last started using a different config file. X-Git-Tag: 2.0.beta2~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b18ae551081cc834940308588700156346b10a12;p=thirdparty%2Fdovecot%2Fcore.git doveconf: Log a warning if Dovecot was last started using a different config file. --HG-- branch : HEAD --- diff --git a/src/config/doveconf.c b/src/config/doveconf.c index 0b9c99b8d5..c141e7888c 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -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_human(struct ostream *output, 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 config_filter *filter, const char *arg) } } +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 --git a/src/master/main.c b/src/master/main.c index 80be1816fe..53bde4e376 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -276,6 +276,20 @@ static void create_pid_file(const char *path) (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);