]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
master: Move master_set_import_environment() to lib-master
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 7 Jun 2017 21:24:19 +0000 (00:24 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 14 Sep 2017 09:14:53 +0000 (12:14 +0300)
src/lib-master/master-service.c
src/lib-master/master-service.h
src/master/main.c

index b5e92f9101e6a044269a927725ee7d698dc307c2..e075a6e60ee84ecdd4e965af756c54aeebf44087 100644 (file)
@@ -551,6 +551,37 @@ void master_service_init_finish(struct master_service *service)
        master_status_update(service);
 }
 
+void master_service_import_environment(const char *import_environment)
+{
+       const char *const *envs, *key, *value;
+       ARRAY_TYPE(const_string) keys;
+
+       if (*import_environment == '\0')
+               return;
+
+       t_array_init(&keys, 8);
+       /* preserve existing DOVECOT_PRESERVE_ENVS */
+       value = getenv(DOVECOT_PRESERVE_ENVS_ENV);
+       if (value != NULL)
+               array_append(&keys, &value, 1);
+       /* add new environments */
+       envs = t_strsplit_spaces(import_environment, " ");
+       for (; *envs != NULL; envs++) {
+               value = strchr(*envs, '=');
+               if (value == NULL)
+                       key = *envs;
+               else {
+                       key = t_strdup_until(*envs, value);
+                       env_put(*envs);
+               }
+               array_append(&keys, &key, 1);
+       }
+       array_append_zero(&keys);
+
+       value = t_strarray_join(array_idx(&keys, 0), " ");
+       env_put(t_strconcat(DOVECOT_PRESERVE_ENVS_ENV"=", value, NULL));
+}
+
 void master_service_env_clean(void)
 {
        const char *value = getenv(DOVECOT_PRESERVE_ENVS_ENV);
index 6385911a5971d45d130491f3ebe5a7d286174bb3..9d49651a799c6a1e267ffc473fb90ce8fc5913ee 100644 (file)
@@ -91,6 +91,11 @@ bool master_service_parse_option(struct master_service *service,
    initialization code is finished. */
 void master_service_init_finish(struct master_service *service);
 
+/* import_environment is a space-separated list of environment keys or
+   key=values. The key=values are immediately added to the environment.
+   All the keys are added to DOVECOT_PRESERVE_ENVS environment so they're
+   preserved by master_service_env_clean(). */
+void master_service_import_environment(const char *import_environment);
 /* Clean environment from everything except the ones listed in
    DOVECOT_PRESERVE_ENVS environment. */
 void master_service_env_clean(void);
index bfb608349ba52bcae73d3ca4c0d8a9605f7b128a..a32ca57ae78cde436b3aa60858f88a0c3f68ea81 100644 (file)
@@ -421,38 +421,6 @@ static struct master_settings *master_settings_read(void)
        return master_service_settings_get_others(master_service)[0];
 }
 
-static void
-master_set_import_environment(const struct master_service_settings *set)
-{
-       const char *const *envs, *key, *value;
-       ARRAY_TYPE(const_string) keys;
-
-       if (*set->import_environment == '\0')
-               return;
-
-       t_array_init(&keys, 8);
-       /* preserve existing DOVECOT_PRESERVE_ENVS */
-       value = getenv(DOVECOT_PRESERVE_ENVS_ENV);
-       if (value != NULL)
-               array_append(&keys, &value, 1);
-       /* add new environments */
-       envs = t_strsplit_spaces(set->import_environment, " ");
-       for (; *envs != NULL; envs++) {
-               value = strchr(*envs, '=');
-               if (value == NULL)
-                       key = *envs;
-               else {
-                       key = t_strdup_until(*envs, value);
-                       env_put(*envs);
-               }
-               array_append(&keys, &key, 1);
-       }
-       array_append_zero(&keys);
-
-       value = t_strarray_join(array_idx(&keys, 0), " ");
-       env_put(t_strconcat(DOVECOT_PRESERVE_ENVS_ENV"=", value, NULL));
-}
-
 static void main_log_startup(char **protocols)
 {
 #define STARTUP_STRING PACKAGE_NAME" v"DOVECOT_VERSION_FULL" starting up"
@@ -851,7 +819,9 @@ int main(int argc, char *argv[])
        fatal_log_check(set);
 
        T_BEGIN {
-               master_set_import_environment(master_service_settings_get(master_service));
+               const struct master_service_settings *service_set =
+                       master_service_settings_get(master_service);
+               master_service_import_environment(service_set->import_environment);
        } T_END;
        master_service_env_clean();