From: Timo Sirainen Date: Wed, 7 Jun 2017 21:24:19 +0000 (+0300) Subject: master: Move master_set_import_environment() to lib-master X-Git-Tag: 2.3.0.rc1~1457 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8a0a8c982a6ffc75a4b1c8717b6180a811655794;p=thirdparty%2Fdovecot%2Fcore.git master: Move master_set_import_environment() to lib-master --- diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 81306ad274..ff63d5309e 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -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); diff --git a/src/lib-master/master-service.h b/src/lib-master/master-service.h index 98746f01f8..51b4e0207b 100644 --- a/src/lib-master/master-service.h +++ b/src/lib-master/master-service.h @@ -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); diff --git a/src/master/main.c b/src/master/main.c index 0ce87462dd..c7c974e16c 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -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();