From b4c14404b3e8753c41bac0b1d49369230a15c544 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Sun, 6 Sep 2015 23:06:53 -0700 Subject: execute: Add new PassEnvironment= directive This directive allows passing environment variables from the system manager to spawned services. Variables in the system manager can be set inside a container by passing `--set-env=...` options to systemd-spawn. Tested with an on-disk test.service unit. Tested using multiple variable names on a single line, with an empty setting to clear the current list of variables, with non-existing variables. Tested using `systemd-run -p PassEnvironment=VARNAME` to confirm it works with transient units. Confirmed that `systemctl show` will display the PassEnvironment settings. Checked that man pages are generated correctly. No regressions in `make check`. --- src/shared/bus-util.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/shared/bus-util.c') diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index a13991a960..73ceeba18f 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1654,7 +1654,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen r = sd_bus_message_append(m, "v", "i", i); - } else if (streq(field, "Environment")) { + } else if (STR_IN_SET(field, "Environment", "PassEnvironment")) { const char *p; r = sd_bus_message_open_container(m, 'v', "as"); @@ -1678,9 +1678,16 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen if (r == 0) break; - if (!env_assignment_is_valid(word)) { - log_error("Invalid environment assignment: %s", eq); - return -EINVAL; + if (streq(field, "Environment")) { + if (!env_assignment_is_valid(word)) { + log_error("Invalid environment assignment: %s", word); + return -EINVAL; + } + } else { /* PassEnvironment */ + if (!env_name_is_valid(word)) { + log_error("Invalid environment variable name: %s", word); + return -EINVAL; + } } r = sd_bus_message_append_basic(m, 's', word); -- cgit v1.2.3-54-g00ecf