summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/execute.c2
-rw-r--r--src/load-fragment.c2
-rw-r--r--src/strv.c23
-rw-r--r--src/strv.h2
-rw-r--r--src/test-env-replace.c21
5 files changed, 47 insertions, 3 deletions
diff --git a/src/execute.c b/src/execute.c
index 05abd5aaac..8f486e2004 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -1303,6 +1303,8 @@ int exec_spawn(ExecCommand *command,
goto fail;
}
+ final_env = strv_env_clean(final_env);
+
execve(command->path, final_argv, final_env);
r = EXIT_EXEC;
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 334dd68146..261180d155 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1399,7 +1399,7 @@ static int config_parse_env_file(
goto finish;
}
- t = strv_env_set(*env, u);
+ t = strv_append(*env, u);
free(u);
if (!t) {
diff --git a/src/strv.c b/src/strv.c
index d9aef98224..d1c7b2c32d 100644
--- a/src/strv.c
+++ b/src/strv.c
@@ -380,7 +380,7 @@ static int env_append(char **r, char ***k, char **a) {
/* Add the entries of a to *k unless they already exist in *r
* in which case they are overriden instead. This assumes
- * there is enough space in the r */
+ * there is enough space in the r array. */
for (; *a; a++) {
char **j;
@@ -556,3 +556,24 @@ char *strv_env_get_with_length(char **l, const char *name, size_t k) {
char *strv_env_get(char **l, const char *name) {
return strv_env_get_with_length(l, name, strlen(name));
}
+
+char **strv_env_clean(char **l) {
+ char **r, **ret;
+
+ for (r = ret = l; *l; l++) {
+ const char *equal;
+
+ equal = strchr(*l, '=');
+
+ if (equal && equal[1] == 0) {
+ free(*l);
+ continue;
+ }
+
+ *(r++) = *l;
+ }
+
+ *r = NULL;
+
+ return ret;
+}
diff --git a/src/strv.h b/src/strv.h
index 1103e194c3..5af84ee41f 100644
--- a/src/strv.h
+++ b/src/strv.h
@@ -63,6 +63,8 @@ char **strv_env_set(char **x, const char *p);
char *strv_env_get_with_length(char **l, const char *name, size_t k);
char *strv_env_get(char **x, const char *n);
+char **strv_env_clean(char **l);
+
#define STRV_FOREACH(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
diff --git a/src/test-env-replace.c b/src/test-env-replace.c
index 37dd7ff590..4188c67dde 100644
--- a/src/test-env-replace.c
+++ b/src/test-env-replace.c
@@ -47,7 +47,7 @@ int main(int argc, char *argv[]) {
NULL
};
- char **i, **r, *t;
+ char **i, **r, *t, **a, **b;
r = replace_env_argv((char**) line, (char**) env);
@@ -96,5 +96,24 @@ int main(int argc, char *argv[]) {
printf("%s\n", t);
free(t);
+ a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL);
+ b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL);
+
+ r = strv_env_merge(2, a, b);
+ strv_free(a);
+ strv_free(b);
+
+ STRV_FOREACH(i, r)
+ printf("%s\n", *i);
+
+ printf("CLEANED UP:\n");
+
+ r = strv_env_clean(r);
+
+ STRV_FOREACH(i, r)
+ printf("%s\n", *i);
+
+ strv_free(r);
+
return 0;
}