|
|
923a60 |
From 88d2ec272d3e503412e477d9abaebfe2ca199e78 Mon Sep 17 00:00:00 2001
|
|
|
923a60 |
From: Filipe Brandenburger <filbranden@google.com>
|
|
|
923a60 |
Date: Sun, 6 Sep 2015 23:06:53 -0700
|
|
|
923a60 |
Subject: [PATCH] execute: Add new PassEnvironment= directive
|
|
|
923a60 |
|
|
|
923a60 |
This directive allows passing environment variables from the system
|
|
|
923a60 |
manager to spawned services. Variables in the system manager can be set
|
|
|
923a60 |
inside a container by passing `--set-env=...` options to systemd-spawn.
|
|
|
923a60 |
|
|
|
923a60 |
Tested with an on-disk test.service unit. Tested using multiple variable
|
|
|
923a60 |
names on a single line, with an empty setting to clear the current list
|
|
|
923a60 |
of variables, with non-existing variables.
|
|
|
923a60 |
|
|
|
923a60 |
Tested using `systemd-run -p PassEnvironment=VARNAME` to confirm it
|
|
|
923a60 |
works with transient units.
|
|
|
923a60 |
|
|
|
923a60 |
Confirmed that `systemctl show` will display the PassEnvironment
|
|
|
923a60 |
settings.
|
|
|
923a60 |
|
|
|
923a60 |
Checked that man pages are generated correctly.
|
|
|
923a60 |
|
|
|
923a60 |
No regressions in `make check`.
|
|
|
923a60 |
|
|
|
923a60 |
(cherry picked from commit b4c14404b3e8753c41bac0b1d49369230a15c544)
|
|
|
923a60 |
|
|
|
923a60 |
Resolves: #1426214
|
|
|
923a60 |
---
|
|
|
923a60 |
man/systemd.exec.xml | 27 +++++++++++
|
|
|
923a60 |
shell-completion/bash/systemd-run | 2 +-
|
|
|
923a60 |
src/core/dbus-execute.c | 34 ++++++++++++++
|
|
|
923a60 |
src/core/execute.c | 44 +++++++++++++++++-
|
|
|
923a60 |
src/core/execute.h | 1 +
|
|
|
923a60 |
src/core/load-fragment-gperf.gperf.m4 | 1 +
|
|
|
923a60 |
src/core/load-fragment.c | 65 +++++++++++++++++++++++++++
|
|
|
923a60 |
src/core/load-fragment.h | 1 +
|
|
|
923a60 |
src/libsystemd/sd-bus/bus-util.c | 2 +-
|
|
|
923a60 |
src/shared/env-util.c | 15 +++++++
|
|
|
923a60 |
src/shared/env-util.h | 1 +
|
|
|
923a60 |
11 files changed, 189 insertions(+), 4 deletions(-)
|
|
|
923a60 |
|
|
|
923a60 |
diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
|
|
|
923a60 |
index c5199d3a54..aa5831cc2c 100644
|
|
|
923a60 |
--- a/man/systemd.exec.xml
|
|
|
923a60 |
+++ b/man/systemd.exec.xml
|
|
|
923a60 |
@@ -293,6 +293,33 @@
|
|
|
923a60 |
earlier setting.</para></listitem>
|
|
|
923a60 |
</varlistentry>
|
|
|
923a60 |
|
|
|
923a60 |
+ <varlistentry>
|
|
|
923a60 |
+ <term><varname>PassEnvironment=</varname></term>
|
|
|
923a60 |
+
|
|
|
923a60 |
+ <listitem><para>Pass environment variables from the systemd system
|
|
|
923a60 |
+ manager to executed processes. Takes a space-separated list of variable
|
|
|
923a60 |
+ names. This option may be specified more than once, in which case all
|
|
|
923a60 |
+ listed variables will be set. If the empty string is assigned to this
|
|
|
923a60 |
+ option, the list of environment variables is reset, all prior
|
|
|
923a60 |
+ assignments have no effect. Variables that are not set in the system
|
|
|
923a60 |
+ manager will not be passed and will be silently ignored.</para>
|
|
|
923a60 |
+
|
|
|
923a60 |
+ <para>Variables passed from this setting are overridden by those passed
|
|
|
923a60 |
+ from <varname>Environment=</varname> or
|
|
|
923a60 |
+ <varname>EnvironmentFile=</varname>.</para>
|
|
|
923a60 |
+
|
|
|
923a60 |
+ <para>Example:
|
|
|
923a60 |
+ <programlisting>PassEnvironment=VAR1 VAR2 VAR3</programlisting>
|
|
|
923a60 |
+ passes three variables <literal>VAR1</literal>,
|
|
|
923a60 |
+ <literal>VAR2</literal>, <literal>VAR3</literal>
|
|
|
923a60 |
+ with the values set for those variables in PID1.</para>
|
|
|
923a60 |
+
|
|
|
923a60 |
+ <para>
|
|
|
923a60 |
+ See
|
|
|
923a60 |
+ <citerefentry project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry>
|
|
|
923a60 |
+ for details about environment variables.</para></listitem>
|
|
|
923a60 |
+ </varlistentry>
|
|
|
923a60 |
+
|
|
|
923a60 |
<varlistentry>
|
|
|
923a60 |
<term><varname>StandardInput=</varname></term>
|
|
|
923a60 |
<listitem><para>Controls where file descriptor 0 (STDIN) of
|
|
|
923a60 |
diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run
|
|
|
923a60 |
index 5145cd3f29..36ffa46db5 100644
|
|
|
923a60 |
--- a/shell-completion/bash/systemd-run
|
|
|
923a60 |
+++ b/shell-completion/bash/systemd-run
|
|
|
923a60 |
@@ -73,7 +73,7 @@ _systemd_run() {
|
|
|
923a60 |
KillSignal= LimitCPU= LimitFSIZE= LimitDATA= LimitSTACK=
|
|
|
923a60 |
LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC=
|
|
|
923a60 |
LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE=
|
|
|
923a60 |
- LimitNICE= LimitRTPRIO= LimitRTTIME='
|
|
|
923a60 |
+ LimitNICE= LimitRTPRIO= LimitRTTIME= PassEnvironment='
|
|
|
923a60 |
|
|
|
923a60 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
|
|
|
923a60 |
return 0
|
|
|
923a60 |
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
|
|
|
923a60 |
index a9f7971cde..da8b10d2b3 100644
|
|
|
923a60 |
--- a/src/core/dbus-execute.c
|
|
|
923a60 |
+++ b/src/core/dbus-execute.c
|
|
|
923a60 |
@@ -597,6 +597,7 @@ const sd_bus_vtable bus_exec_vtable[] = {
|
|
|
923a60 |
SD_BUS_VTABLE_START(0),
|
|
|
923a60 |
SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
923a60 |
SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
923a60 |
+ SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
923a60 |
SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
923a60 |
SD_BUS_PROPERTY("LimitCPU", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
923a60 |
SD_BUS_PROPERTY("LimitFSIZE", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
923a60 |
@@ -963,6 +964,39 @@ int bus_exec_context_set_transient_property(
|
|
|
923a60 |
|
|
|
923a60 |
return 1;
|
|
|
923a60 |
|
|
|
923a60 |
+ } else if (streq(name, "PassEnvironment")) {
|
|
|
923a60 |
+
|
|
|
923a60 |
+ _cleanup_strv_free_ char **l = NULL;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ r = sd_bus_message_read_strv(message, &l);
|
|
|
923a60 |
+ if (r < 0)
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (!strv_env_name_is_valid(l))
|
|
|
923a60 |
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment block.");
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (mode != UNIT_CHECK) {
|
|
|
923a60 |
+ if (strv_isempty(l)) {
|
|
|
923a60 |
+ strv_free(c->pass_environment);
|
|
|
923a60 |
+ c->pass_environment = NULL;
|
|
|
923a60 |
+ unit_write_drop_in_private_format(u, mode, name, "PassEnvironment=\n");
|
|
|
923a60 |
+ } else {
|
|
|
923a60 |
+ _cleanup_free_ char *joined = NULL;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ r = strv_extend_strv(&c->pass_environment, l);
|
|
|
923a60 |
+ if (r < 0)
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ joined = strv_join_quoted(c->pass_environment);
|
|
|
923a60 |
+ if (!joined)
|
|
|
923a60 |
+ return -ENOMEM;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ unit_write_drop_in_private_format(u, mode, name, "PassEnvironment=%s\n", joined);
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ return 1;
|
|
|
923a60 |
+
|
|
|
923a60 |
} else if (rlimit_from_string(name) >= 0) {
|
|
|
923a60 |
uint64_t rl;
|
|
|
923a60 |
rlim_t x;
|
|
|
923a60 |
diff --git a/src/core/execute.c b/src/core/execute.c
|
|
|
923a60 |
index 863babd761..f72b20966f 100644
|
|
|
923a60 |
--- a/src/core/execute.c
|
|
|
923a60 |
+++ b/src/core/execute.c
|
|
|
923a60 |
@@ -1256,6 +1256,34 @@ static int build_environment(
|
|
|
923a60 |
return 0;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
+static int build_pass_environment(const ExecContext *c, char ***ret) {
|
|
|
923a60 |
+ _cleanup_strv_free_ char **pass_env = NULL;
|
|
|
923a60 |
+ size_t n_env = 0, n_bufsize = 0;
|
|
|
923a60 |
+ char **i;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ STRV_FOREACH(i, c->pass_environment) {
|
|
|
923a60 |
+ _cleanup_free_ char *x = NULL;
|
|
|
923a60 |
+ char *v;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ v = getenv(*i);
|
|
|
923a60 |
+ if (!v)
|
|
|
923a60 |
+ continue;
|
|
|
923a60 |
+ x = strjoin(*i, "=", v, NULL);
|
|
|
923a60 |
+ if (!x)
|
|
|
923a60 |
+ return -ENOMEM;
|
|
|
923a60 |
+ if (!GREEDY_REALLOC(pass_env, n_bufsize, n_env + 2))
|
|
|
923a60 |
+ return -ENOMEM;
|
|
|
923a60 |
+ pass_env[n_env++] = x;
|
|
|
923a60 |
+ pass_env[n_env] = NULL;
|
|
|
923a60 |
+ x = NULL;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ *ret = pass_env;
|
|
|
923a60 |
+ pass_env = NULL;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ return 0;
|
|
|
923a60 |
+}
|
|
|
923a60 |
+
|
|
|
923a60 |
static bool exec_needs_mount_namespace(
|
|
|
923a60 |
const ExecContext *context,
|
|
|
923a60 |
const ExecParameters *params,
|
|
|
923a60 |
@@ -1297,7 +1325,7 @@ static int exec_child(
|
|
|
923a60 |
char **files_env,
|
|
|
923a60 |
int *exit_status) {
|
|
|
923a60 |
|
|
|
923a60 |
- _cleanup_strv_free_ char **our_env = NULL, **pam_env = NULL, **final_env = NULL, **final_argv = NULL;
|
|
|
923a60 |
+ _cleanup_strv_free_ char **our_env = NULL, **pass_env = NULL, **pam_env = NULL, **final_env = NULL, **final_argv = NULL;
|
|
|
923a60 |
_cleanup_free_ char *mac_selinux_context_net = NULL;
|
|
|
923a60 |
const char *username = NULL, *home = NULL, *shell = NULL;
|
|
|
923a60 |
unsigned n_dont_close = 0;
|
|
|
923a60 |
@@ -1805,9 +1833,16 @@ static int exec_child(
|
|
|
923a60 |
return r;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
- final_env = strv_env_merge(5,
|
|
|
923a60 |
+ r = build_pass_environment(context, &pass_env);
|
|
|
923a60 |
+ if (r < 0) {
|
|
|
923a60 |
+ *exit_status = EXIT_MEMORY;
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ final_env = strv_env_merge(6,
|
|
|
923a60 |
params->environment,
|
|
|
923a60 |
our_env,
|
|
|
923a60 |
+ pass_env,
|
|
|
923a60 |
context->environment,
|
|
|
923a60 |
files_env,
|
|
|
923a60 |
pam_env,
|
|
|
923a60 |
@@ -1965,6 +2000,8 @@ void exec_context_done(ExecContext *c) {
|
|
|
923a60 |
|
|
|
923a60 |
strv_free(c->environment_files);
|
|
|
923a60 |
c->environment_files = NULL;
|
|
|
923a60 |
+ strv_free(c->pass_environment);
|
|
|
923a60 |
+ c->pass_environment = NULL;
|
|
|
923a60 |
|
|
|
923a60 |
for (l = 0; l < ELEMENTSOF(c->rlimit); l++) {
|
|
|
923a60 |
free(c->rlimit[l]);
|
|
|
923a60 |
@@ -2267,6 +2304,9 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
|
|
|
923a60 |
STRV_FOREACH(e, c->environment_files)
|
|
|
923a60 |
fprintf(f, "%sEnvironmentFile: %s\n", prefix, *e);
|
|
|
923a60 |
|
|
|
923a60 |
+ STRV_FOREACH(e, c->pass_environment)
|
|
|
923a60 |
+ fprintf(f, "%sPassEnvironment: %s\n", prefix, *e);
|
|
|
923a60 |
+
|
|
|
923a60 |
if (c->nice_set)
|
|
|
923a60 |
fprintf(f,
|
|
|
923a60 |
"%sNice: %i\n",
|
|
|
923a60 |
diff --git a/src/core/execute.h b/src/core/execute.h
|
|
|
923a60 |
index 6e0c9faa75..cadd0e6b47 100644
|
|
|
923a60 |
--- a/src/core/execute.h
|
|
|
923a60 |
+++ b/src/core/execute.h
|
|
|
923a60 |
@@ -96,6 +96,7 @@ struct ExecRuntime {
|
|
|
923a60 |
struct ExecContext {
|
|
|
923a60 |
char **environment;
|
|
|
923a60 |
char **environment_files;
|
|
|
923a60 |
+ char **pass_environment;
|
|
|
923a60 |
|
|
|
923a60 |
struct rlimit *rlimit[_RLIMIT_MAX];
|
|
|
923a60 |
char *working_directory, *root_directory;
|
|
|
923a60 |
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
|
|
|
923a60 |
index c866a9cd02..b50fe45b47 100644
|
|
|
923a60 |
--- a/src/core/load-fragment-gperf.gperf.m4
|
|
|
923a60 |
+++ b/src/core/load-fragment-gperf.gperf.m4
|
|
|
923a60 |
@@ -33,6 +33,7 @@ $1.CPUAffinity, config_parse_exec_cpu_affinity, 0,
|
|
|
923a60 |
$1.UMask, config_parse_mode, 0, offsetof($1, exec_context.umask)
|
|
|
923a60 |
$1.Environment, config_parse_environ, 0, offsetof($1, exec_context.environment)
|
|
|
923a60 |
$1.EnvironmentFile, config_parse_unit_env_file, 0, offsetof($1, exec_context.environment_files)
|
|
|
923a60 |
+$1.PassEnvironment, config_parse_pass_environ, 0, offsetof($1, exec_context.pass_environment)
|
|
|
923a60 |
$1.StandardInput, config_parse_input, 0, offsetof($1, exec_context.std_input)
|
|
|
923a60 |
$1.StandardOutput, config_parse_output, 0, offsetof($1, exec_context.std_output)
|
|
|
923a60 |
$1.StandardError, config_parse_output, 0, offsetof($1, exec_context.std_error)
|
|
|
923a60 |
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
|
|
|
923a60 |
index 3a3c456da5..c450fe2c72 100644
|
|
|
923a60 |
--- a/src/core/load-fragment.c
|
|
|
923a60 |
+++ b/src/core/load-fragment.c
|
|
|
923a60 |
@@ -2265,6 +2265,71 @@ int config_parse_environ(const char *unit,
|
|
|
923a60 |
return 0;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
+int config_parse_pass_environ(const char *unit,
|
|
|
923a60 |
+ const char *filename,
|
|
|
923a60 |
+ unsigned line,
|
|
|
923a60 |
+ const char *section,
|
|
|
923a60 |
+ unsigned section_line,
|
|
|
923a60 |
+ const char *lvalue,
|
|
|
923a60 |
+ int ltype,
|
|
|
923a60 |
+ const char *rvalue,
|
|
|
923a60 |
+ void *data,
|
|
|
923a60 |
+ void *userdata) {
|
|
|
923a60 |
+
|
|
|
923a60 |
+ const char *whole_rvalue = rvalue;
|
|
|
923a60 |
+ char*** passenv = data;
|
|
|
923a60 |
+ _cleanup_strv_free_ char **n = NULL;
|
|
|
923a60 |
+ size_t nlen = 0, nbufsize = 0;
|
|
|
923a60 |
+ int r;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ assert(filename);
|
|
|
923a60 |
+ assert(lvalue);
|
|
|
923a60 |
+ assert(rvalue);
|
|
|
923a60 |
+ assert(data);
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (isempty(rvalue)) {
|
|
|
923a60 |
+ /* Empty assignment resets the list */
|
|
|
923a60 |
+ strv_free(*passenv);
|
|
|
923a60 |
+ *passenv = NULL;
|
|
|
923a60 |
+ return 0;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ for (;;) {
|
|
|
923a60 |
+ _cleanup_free_ char *word = NULL;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
|
|
|
923a60 |
+ if (r == 0)
|
|
|
923a60 |
+ break;
|
|
|
923a60 |
+ if (r == -ENOMEM)
|
|
|
923a60 |
+ return log_oom();
|
|
|
923a60 |
+ if (r < 0) {
|
|
|
923a60 |
+ log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
923a60 |
+ "Trailing garbage in %s, ignoring: %s", lvalue, whole_rvalue);
|
|
|
923a60 |
+ break;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (!env_name_is_valid(word)) {
|
|
|
923a60 |
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
|
|
923a60 |
+ "Invalid environment name for %s, ignoring: %s", lvalue, word);
|
|
|
923a60 |
+ continue;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
|
|
|
923a60 |
+ return log_oom();
|
|
|
923a60 |
+ n[nlen++] = word;
|
|
|
923a60 |
+ n[nlen] = NULL;
|
|
|
923a60 |
+ word = NULL;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (n) {
|
|
|
923a60 |
+ r = strv_extend_strv(passenv, n);
|
|
|
923a60 |
+ if (r < 0)
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ return 0;
|
|
|
923a60 |
+}
|
|
|
923a60 |
+
|
|
|
923a60 |
int config_parse_ip_tos(const char *unit,
|
|
|
923a60 |
const char *filename,
|
|
|
923a60 |
unsigned line,
|
|
|
923a60 |
diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
|
|
|
923a60 |
index 7c69e53699..9dd7d1bda0 100644
|
|
|
923a60 |
--- a/src/core/load-fragment.h
|
|
|
923a60 |
+++ b/src/core/load-fragment.h
|
|
|
923a60 |
@@ -85,6 +85,7 @@ int config_parse_syscall_filter(const char *unit, const char *filename, unsigned
|
|
|
923a60 |
int config_parse_syscall_archs(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
|
923a60 |
int config_parse_syscall_errno(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
|
923a60 |
int config_parse_environ(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
|
923a60 |
+int config_parse_pass_environ(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
|
923a60 |
int config_parse_unit_slice(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
|
923a60 |
int config_parse_cpu_shares(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
|
923a60 |
int config_parse_memory_limit(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
|
923a60 |
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
|
|
|
923a60 |
index d357760870..ed0849b638 100644
|
|
|
923a60 |
--- a/src/libsystemd/sd-bus/bus-util.c
|
|
|
923a60 |
+++ b/src/libsystemd/sd-bus/bus-util.c
|
|
|
923a60 |
@@ -1535,7 +1535,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
|
|
|
923a60 |
|
|
|
923a60 |
r = sd_bus_message_append(m, "v", "i", i);
|
|
|
923a60 |
|
|
|
923a60 |
- } else if (streq(field, "Environment")) {
|
|
|
923a60 |
+ } else if (STR_IN_SET(field, "Environment", "PassEnvironment")) {
|
|
|
923a60 |
|
|
|
923a60 |
r = sd_bus_message_append(m, "v", "as", 1, eq);
|
|
|
923a60 |
|
|
|
923a60 |
diff --git a/src/shared/env-util.c b/src/shared/env-util.c
|
|
|
923a60 |
index e8da4c978a..581d84a20b 100644
|
|
|
923a60 |
--- a/src/shared/env-util.c
|
|
|
923a60 |
+++ b/src/shared/env-util.c
|
|
|
923a60 |
@@ -136,6 +136,21 @@ bool strv_env_is_valid(char **e) {
|
|
|
923a60 |
return true;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
+bool strv_env_name_is_valid(char **l) {
|
|
|
923a60 |
+ char **p, **q;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ STRV_FOREACH(p, l) {
|
|
|
923a60 |
+ if (!env_name_is_valid(*p))
|
|
|
923a60 |
+ return false;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ STRV_FOREACH(q, p + 1)
|
|
|
923a60 |
+ if (streq(*p, *q))
|
|
|
923a60 |
+ return false;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
+ return true;
|
|
|
923a60 |
+}
|
|
|
923a60 |
+
|
|
|
923a60 |
bool strv_env_name_or_assignment_is_valid(char **l) {
|
|
|
923a60 |
char **p, **q;
|
|
|
923a60 |
|
|
|
923a60 |
diff --git a/src/shared/env-util.h b/src/shared/env-util.h
|
|
|
923a60 |
index 252d87be1f..b8c2d81e4a 100644
|
|
|
923a60 |
--- a/src/shared/env-util.h
|
|
|
923a60 |
+++ b/src/shared/env-util.h
|
|
|
923a60 |
@@ -34,6 +34,7 @@ bool strv_env_is_valid(char **e);
|
|
|
923a60 |
#define strv_env_clean(l) strv_env_clean_with_callback(l, NULL, NULL)
|
|
|
923a60 |
char **strv_env_clean_with_callback(char **l, void (*invalid_callback)(const char *p, void *userdata), void *userdata);
|
|
|
923a60 |
|
|
|
923a60 |
+bool strv_env_name_is_valid(char **l);
|
|
|
923a60 |
bool strv_env_name_or_assignment_is_valid(char **l);
|
|
|
923a60 |
|
|
|
923a60 |
char **strv_env_merge(unsigned n_lists, ...);
|