summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-01-19 14:20:16 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-01-19 14:24:51 +0100
commite9155cd0778499a7e20edd2af8429247bbb1daa9 (patch)
tree5b8cfc54a6623b7d6e587705916d48e148d6920b /src/systemctl
parent30927a24848c4d727f7619cc74b878f098cdd724 (diff)
downloadsystemd-e9155cd0778499a7e20edd2af8429247bbb1daa9.tar.gz
systemctl: warn when importing environment variables with control characters
I don't think it is useful to warn about about environemnt variables where the user explicitly configured some value. If they went through the effort of escaping the cc to include it in the setting (e.g. Environment="VAR=\efoo"), and we pass this through, there isn't anything to warn about. This also applies to 'systemctl set-environment', where the variable name and value are passed as arguments. The only case where the warning *might* be useful is where the user might be surprised by the value. This occurs when importing variables from the inherited environment, i.e. in 'systemctl import-environment'. In not convinced that this is useful, since the user better control their shell environment anyway. $ systemctl import-environment Calling import-environment without a list of variable names is deprecated. Environment variable $LESS_TERMCAP_mb contains control characters, importing anyway. Environment variable $LESS_TERMCAP_md contains control characters, importing anyway. Environment variable $LESS_TERMCAP_me contains control characters, importing anyway. Environment variable $LESS_TERMCAP_se contains control characters, importing anyway. Environment variable $LESS_TERMCAP_so contains control characters, importing anyway. Environment variable $LESS_TERMCAP_ue contains control characters, importing anyway. Environment variable $LESS_TERMCAP_us contains control characters, importing anyway. Environment variable $ZZZ contains control characters, importing anyway.
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl-set-environment.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/systemctl/systemctl-set-environment.c b/src/systemctl/systemctl-set-environment.c
index 437236efb4..bfd87c0cdd 100644
--- a/src/systemctl/systemctl-set-environment.c
+++ b/src/systemctl/systemctl-set-environment.c
@@ -127,6 +127,12 @@ int import_environment(int argc, char *argv[], void *userdata) {
strv_env_clean_with_callback(copy, invalid_callback, NULL);
+ char **e;
+ STRV_FOREACH(e, copy)
+ if (string_has_cc(*e, NULL))
+ log_notice("Environment variable $%.*s contains control characters, importing anyway.",
+ (int) strcspn(*e, "="), *e);
+
r = sd_bus_message_append_strv(m, copy);
} else {
@@ -148,6 +154,10 @@ int import_environment(int argc, char *argv[], void *userdata) {
eq = startswith(*b, *a);
if (eq && *eq == '=') {
+ if (string_has_cc(eq + 1, NULL))
+ log_notice("Environment variable $%.*s contains control characters, importing anyway.",
+ (int) (eq - *b), *b);
+
r = sd_bus_message_append(m, "s", *b);
if (r < 0)
return bus_log_create_error(r);