}
}
+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);
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);
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"
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();