mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-26 10:03:40 +03:00
execute: drop empty assignments from env blocks on execution but keep them around otherwise to make them visible
This commit is contained in:
parent
7fc942b29e
commit
a6ff950e71
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
23
src/strv.c
23
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;
|
||||
}
|
||||
|
@ -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)++)
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user