]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveconf: Log a warning if Dovecot was last started using a different config file.
authorTimo Sirainen <tss@iki.fi>
Sat, 23 Jan 2010 10:37:35 +0000 (12:37 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 23 Jan 2010 10:37:35 +0000 (12:37 +0200)
--HG--
branch : HEAD

src/config/doveconf.c
src/master/main.c

index 0b9c99b8d5b91a9ec4a6db870337d95a4ae29f90..c141e7888ce9d4e358e38ec156f02003c16923c5 100644 (file)
@@ -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);
 
index 80be1816fe959655db341890495149228a5db6e5..53bde4e3762f2d875f051dc09426389560709725 100644 (file)
@@ -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);