]> 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)
committerGitLab <gitlab@git.dovecot.net>
Sat, 10 Jun 2017 08:35:40 +0000 (11:35 +0300)
src/lib-master/master-service.c
src/lib-master/master-service.h
src/master/main.c

index 81306ad27443aff8fdc674bd46f6c4394be7a7ef..ff63d5309e0abd52daa7f3eb7e06e270aa97c338 100644 (file)
@@ -566,6 +566,37 @@ void master_service_init_finish(struct master_service *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 98746f01f8ce09d462b485ce7eb6404cecdc685d..51b4e0207bdf80799bd9387f1ec0f18c59ac05d3 100644 (file)
@@ -95,6 +95,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 0ce87462dd0b19f79be2c04e31460d120ab24850..c7c974e16c1319d95af8bcf53f4b5143dd01bc05 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"
@@ -852,7 +820,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();