From: Lennart Poettering Date: Wed, 26 May 2021 15:17:11 +0000 (+0200) Subject: core: support specifier expansion in DefaultEnvironment= and ManagerEnvironment= X-Git-Tag: v249-rc1~140^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F19737%2Fhead;p=thirdparty%2Fsystemd.git core: support specifier expansion in DefaultEnvironment= and ManagerEnvironment= Strictly speaking adding this is a compatibility break, given that previously % weren't special. But I'd argue that was simply a bug, as for the much more prominent Environment= service setting we always resolved specifiers, and DEfaultEnvironment= is explicitly listed as being the default for that. Hence, let's fix that. Replaces: #16787 --- diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml index 3f229908c92..2851bae31e7 100644 --- a/man/systemd-system.conf.xml +++ b/man/systemd-system.conf.xml @@ -328,6 +328,9 @@ project='man-pages'>environ7 for details about environment variables. + Simple %-specifier expansion is supported, see below for a list of supported + specifiers. + Example: DefaultEnvironment="VAR1=word1 word2" VAR2=word3 "VAR3=word 5 6" @@ -349,7 +352,11 @@ Setting environment variables for the manager process may be useful to modify its behaviour. See ENVIRONMENT for a descriptions of some - variables understood by systemd. + variables understood by systemd. + + Simple %-specifier expansion is supported, see below for a list of supported + specifiers. + @@ -440,6 +447,45 @@ + + Specifiers + + Specifiers may be used in the DefaultEnvironment= and + ManagerEnvironment= settings. The following expansions are understood: + + Specifiers available + + + + + + + Specifier + Meaning + Details + + + + + + + + + + + + + + + + + + + + +
+
+ See Also diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index ff6eaf32ef6..d31d6420170 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -57,6 +57,7 @@ #include "signal-util.h" #include "socket-bind.h" #include "socket-netlink.h" +#include "specifier.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -2656,15 +2657,15 @@ int config_parse_environ( if (r == 0) return 0; - if (u) { + if (u) r = unit_env_printf(u, word, &resolved); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to resolve unit specifiers in %s, ignoring: %m", word); - continue; - } - } else - resolved = TAKE_PTR(word); + else + r = specifier_printf(word, sc_arg_max(), system_and_tmp_specifier_table, NULL, &resolved); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to resolve specifiers in %s, ignoring: %m", word); + continue; + } if (!env_assignment_is_valid(resolved)) { log_syntax(unit, LOG_WARNING, filename, line, 0,