1
0
mirror of https://github.com/systemd/systemd.git synced 2025-09-10 21:45:06 +03:00

Merge pull request #1616 from evverx/run-fix-environment-parsing

run: fix Environment parsing
This commit is contained in:
Lennart Poettering
2015-10-20 15:26:19 +02:00
2 changed files with 53 additions and 10 deletions

View File

@@ -1155,18 +1155,24 @@ int bus_exec_context_set_transient_property(
_cleanup_free_ char *joined = NULL; _cleanup_free_ char *joined = NULL;
char **e; char **e;
e = strv_env_merge(2, c->environment, l); if (strv_length(l) == 0) {
if (!e) c->environment = strv_free(c->environment);
return -ENOMEM; unit_write_drop_in_private_format(u, mode, name, "Environment=\n");
} else {
e = strv_env_merge(2, c->environment, l);
if (!e)
return -ENOMEM;
strv_free(c->environment); strv_free(c->environment);
c->environment = e; c->environment = e;
joined = strv_join_quoted(c->environment); joined = strv_join_quoted(c->environment);
if (!joined) if (!joined)
return -ENOMEM; return -ENOMEM;
unit_write_drop_in_private_format(u, mode, name, "Environment=%s\n", joined);
}
unit_write_drop_in_private_format(u, mode, name, "Environment=%s\n", joined);
} }
return 1; return 1;

View File

@@ -31,6 +31,7 @@
#include "bus-message.h" #include "bus-message.h"
#include "cgroup-util.h" #include "cgroup-util.h"
#include "def.h" #include "def.h"
#include "env-util.h"
#include "macro.h" #include "macro.h"
#include "missing.h" #include "missing.h"
#include "path-util.h" #include "path-util.h"
@@ -1642,8 +1643,44 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
r = sd_bus_message_append(m, "v", "i", i); r = sd_bus_message_append(m, "v", "i", i);
} else if (streq(field, "Environment")) { } else if (streq(field, "Environment")) {
const char *p;
r = sd_bus_message_append(m, "v", "as", 1, eq); r = sd_bus_message_open_container(m, 'v', "as");
if (r < 0)
return bus_log_create_error(r);
r = sd_bus_message_open_container(m, 'a', "s");
if (r < 0)
return bus_log_create_error(r);
p = eq;
for (;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_CUNESCAPE);
if (r < 0) {
log_error("Failed to parse Environment value %s", eq);
return -EINVAL;
}
if (r == 0)
break;
if (!env_assignment_is_valid(word)) {
log_error("Invalid environment assignment: %s", eq);
return -EINVAL;
}
r = sd_bus_message_append_basic(m, 's', word);
if (r < 0)
return bus_log_create_error(r);
}
r = sd_bus_message_close_container(m);
if (r < 0)
return bus_log_create_error(r);
r = sd_bus_message_close_container(m);
} else if (streq(field, "KillSignal")) { } else if (streq(field, "KillSignal")) {
int sig; int sig;