1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 09:21:26 +03:00

core: allow specifiers to be resolved in Environment= passed over dbus (#6144)

When specifiers are included in the Environment block in StartTransientUnit,
we resolve specifiers on the PID1 side. Nevertheless we store the unresolved
version in the transient unit file, so that it'll be resolved when loading
the unit. I think this looks nicer.

I also removed the writing of the merged Environment block to the transient
file. Afaict, this resulted in variables being written multiple times, but
this needs to be tested properly.

Fixes #5699.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-06-26 05:26:59 -04:00 committed by Lennart Poettering
parent 92369d5eea
commit f900f5825d

View File

@ -45,6 +45,7 @@
#endif #endif
#include "strv.h" #include "strv.h"
#include "syslog-util.h" #include "syslog-util.h"
#include "unit-printf.h"
#include "user-util.h" #include "user-util.h"
#include "utf8.h" #include "utf8.h"
@ -1317,7 +1318,7 @@ int bus_exec_context_set_transient_property(
} else if (streq(name, "Environment")) { } else if (streq(name, "Environment")) {
_cleanup_strv_free_ char **l = NULL; _cleanup_strv_free_ char **l = NULL, **q = NULL;
r = sd_bus_message_read_strv(message, &l); r = sd_bus_message_read_strv(message, &l);
if (r < 0) if (r < 0)
@ -1326,22 +1327,27 @@ int bus_exec_context_set_transient_property(
if (!strv_env_is_valid(l)) if (!strv_env_is_valid(l))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block."); return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
if (mode != UNIT_CHECK) { r = unit_full_printf_strv(u, l, &q);
_cleanup_free_ char *joined = NULL; if (r < 0)
char **e; return r;
if (strv_length(l) == 0) { if (mode != UNIT_CHECK) {
if (strv_length(q) == 0) {
c->environment = strv_free(c->environment); c->environment = strv_free(c->environment);
unit_write_drop_in_private_format(u, mode, name, "Environment="); unit_write_drop_in_private_format(u, mode, name, "Environment=");
} else { } else {
e = strv_env_merge(2, c->environment, l); _cleanup_free_ char *joined = NULL;
char **e;
e = strv_env_merge(2, c->environment, q);
if (!e) if (!e)
return -ENOMEM; return -ENOMEM;
strv_free(c->environment); strv_free(c->environment);
c->environment = e; c->environment = e;
joined = strv_join_quoted(c->environment); /* We write just the new settings out to file, with unresolved specifiers */
joined = strv_join_quoted(q);
if (!joined) if (!joined)
return -ENOMEM; return -ENOMEM;