diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-10-14 18:32:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-14 18:32:22 +0200 |
commit | b0eb40cda4e37a44d288463dc6e3c97d9d31c3a4 (patch) | |
tree | 711cdc78ffbb765ca15a4d64d41451179ba036a8 /src/systemctl | |
parent | Merge pull request #16968 from yuwata/remove-old-device-on-move-event (diff) | |
parent | systemctl: ignore invalid variables in import-environment (diff) | |
download | systemd-b0eb40cda4e37a44d288463dc6e3c97d9d31c3a4.tar.xz systemd-b0eb40cda4e37a44d288463dc6e3c97d9d31c3a4.zip |
Merge pull request #17188 from keszybz/envvars-posix
Follow (mostly) POSIX rules for environment variables
Diffstat (limited to 'src/systemctl')
-rw-r--r-- | src/systemctl/systemctl-set-environment.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/systemctl/systemctl-set-environment.c b/src/systemctl/systemctl-set-environment.c index 462924f5c9..ac1ec7d6fe 100644 --- a/src/systemctl/systemctl-set-environment.c +++ b/src/systemctl/systemctl-set-environment.c @@ -61,6 +61,12 @@ int show_environment(int argc, char *argv[], void *userdata) { return 0; } +static void invalid_callback(const char *p, void *userdata) { + _cleanup_free_ char *t = cescape(p); + + log_debug("Ignoring invalid environment assignment \"%s\".", strnull(t)); +} + int set_environment(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; @@ -112,9 +118,18 @@ int import_environment(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_create_error(r); - if (argc < 2) - r = sd_bus_message_append_strv(m, environ); - else { + if (argc < 2) { + _cleanup_strv_free_ char **copy = NULL; + + copy = strv_copy(environ); + if (!copy) + return log_oom(); + + strv_env_clean_with_callback(copy, invalid_callback, NULL); + + r = sd_bus_message_append_strv(m, copy); + + } else { char **a, **b; r = sd_bus_message_open_container(m, 'a', "s"); |