]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master, config: Move the responsibility of cleaning environment to doveconf
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 7 Jun 2017 21:40:12 +0000 (00:40 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 14 Sep 2017 09:16:17 +0000 (12:16 +0300)
src/config/doveconf.c
src/lib-master/master-service-settings.c

index a54d1845c432ea15d8d3dfc86000f996ee94b432..ab896af3672a2fc8da75af9eb588a0024044326f 100644 (file)
@@ -12,6 +12,7 @@
 #include "str.h"
 #include "strescape.h"
 #include "settings-parser.h"
+#include "master-interface.h"
 #include "master-service.h"
 #include "all-settings.h"
 #include "sysinfo-get.h"
@@ -865,11 +866,21 @@ int main(int argc, char *argv[])
        } else {
                struct config_export_context *ctx;
 
-               env_put("DOVECONF_ENV=1");
                ctx = config_export_init(wanted_modules, CONFIG_DUMP_SCOPE_SET,
                                         CONFIG_DUMP_FLAG_CHECK_SETTINGS,
                                         config_request_putenv, NULL);
                config_export_by_filter(ctx, &filter);
+
+               if (getenv(DOVECOT_PRESERVE_ENVS_ENV) != NULL) {
+                       /* Standalone binary is getting its configuration via
+                          doveconf. Clean the environment before calling it.
+                          Do this only if the environment exists, because
+                          lib-master doesn't set it if it doesn't want the
+                          environment to be cleaned (e.g. -k parameter). */
+                       master_service_env_clean();
+               }
+
+               env_put("DOVECONF_ENV=1");
                if (config_export_finish(&ctx) < 0)
                        i_fatal("Invalid configuration");
                execvp(exec_args[0], exec_args);
index e2345fef3e2b983ef30352954f05e18e0849f9be..5291b91959c9c7740425882784122962e69ac516 100644 (file)
@@ -134,7 +134,14 @@ master_service_exec_config(struct master_service *service,
                        master_service_import_environment("USER");
                if ((service->flags & MASTER_SERVICE_FLAG_STANDALONE) != 0)
                        master_service_import_environment("LOG_STDERR_TIMESTAMP");
-               master_service_env_clean();
+
+               /* doveconf empties the environment before exec()ing us back
+                  if DOVECOT_PRESERVE_ENVS is set, so make sure it is. */
+               if (getenv(DOVECOT_PRESERVE_ENVS_ENV) == NULL)
+                       env_put(DOVECOT_PRESERVE_ENVS_ENV"=");
+       } else {
+               /* make sure doveconf doesn't remove any environment */
+               env_remove(DOVECOT_PRESERVE_ENVS_ENV);
        }
        if (input->use_sysexits)
                env_put("USE_SYSEXITS=1");