summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl-set-environment.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-01-03 21:53:38 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-01-19 14:18:33 +0100
commitc4899ea427fe93b5b2beac8ab10bfee7dfbf2021 (patch)
tree8e2204293020a7ecd952006ceea2bd1191211fd7 /src/systemctl/systemctl-set-environment.c
parent7b5ed18779992a62ac705952b4dc63b783be93b8 (diff)
downloadsystemd-c4899ea427fe93b5b2beac8ab10bfee7dfbf2021.tar.gz
systemctl: print a warning when trying to import a nonexistent variable
I was quite confused what is happening: $ XXX=xxx $ systemctl --user import-environment XXX $ systemctl --user show-environment | grep XXX (nothing) Obviously, 'export XXX' was missing. Without any indication why the export is not happening, this can be hard to figure out. Another option would be to error out. But so far we didn't, and doing that could break some script which optimistically tries to export some variables, if present.
Diffstat (limited to 'src/systemctl/systemctl-set-environment.c')
-rw-r--r--src/systemctl/systemctl-set-environment.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/systemctl/systemctl-set-environment.c b/src/systemctl/systemctl-set-environment.c
index 3be2c57778..437236efb4 100644
--- a/src/systemctl/systemctl-set-environment.c
+++ b/src/systemctl/systemctl-set-environment.c
@@ -139,21 +139,26 @@ int import_environment(int argc, char *argv[], void *userdata) {
STRV_FOREACH(a, strv_skip(argv, 1)) {
if (!env_name_is_valid(*a))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not a valid environment variable name: %s", *a);
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not a valid environment variable name: %s", *a);
+ bool found = false;
STRV_FOREACH(b, environ) {
const char *eq;
eq = startswith(*b, *a);
if (eq && *eq == '=') {
-
r = sd_bus_message_append(m, "s", *b);
if (r < 0)
return bus_log_create_error(r);
+ found = true;
break;
}
}
+
+ if (!found)
+ log_notice("Environment variable $%s not set, ignoring.", *a);
}
r = sd_bus_message_close_container(m);