changeset 22487:e60f0e893992

master: Move master_set_import_environment() to lib-master
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 08 Jun 2017 00:24:19 +0300
parents fe8060e2ad47
children 052396bac097
files src/lib-master/master-service.c src/lib-master/master-service.h src/master/main.c
diffstat 3 files changed, 39 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-master/master-service.c	Thu Jun 08 00:20:38 2017 +0300
+++ b/src/lib-master/master-service.c	Thu Jun 08 00:24:19 2017 +0300
@@ -551,6 +551,37 @@
 	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);
--- a/src/lib-master/master-service.h	Thu Jun 08 00:20:38 2017 +0300
+++ b/src/lib-master/master-service.h	Thu Jun 08 00:24:19 2017 +0300
@@ -91,6 +91,11 @@
    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);
--- a/src/master/main.c	Thu Jun 08 00:20:38 2017 +0300
+++ b/src/master/main.c	Thu Jun 08 00:24:19 2017 +0300
@@ -421,38 +421,6 @@
 	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 @@
 	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();