diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-04-03 14:45:46 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-04-24 10:02:30 +0200 |
commit | 8c41640a71fd03e4a2a45a28e311bbfd08e4c49a (patch) | |
tree | 7937691f56b96933f0026edba5d1d70cea7c3211 /src/core/unit.c | |
parent | core/unit: rename UNIT_ESCAPE_EXEC_SYNTAX → *_ENV (diff) | |
download | systemd-8c41640a71fd03e4a2a45a28e311bbfd08e4c49a.tar.xz systemd-8c41640a71fd03e4a2a45a28e311bbfd08e4c49a.zip |
core/unit: add UNIT_ESCAPE_EXEC_SYNTAX
Unfortunately we can't escape $ when ':' is used to prohibit variable expansion:
ExecStart=:echo $$
is not the same as
ExecStart=:echo $
This just adds the functionality and the unittests, without using it anywhere
for real yet.
Diffstat (limited to 'src/core/unit.c')
-rw-r--r-- | src/core/unit.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/core/unit.c b/src/core/unit.c index a6a0328e4d..6e20e86a63 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -36,6 +36,7 @@ #include "load-dropin.h" #include "load-fragment.h" #include "log.h" +#include "logarithm.h" #include "macro.h" #include "missing_audit.h" #include "mkdir-label.h" @@ -4312,7 +4313,7 @@ static const char* unit_drop_in_dir(Unit *u, UnitWriteFlags flags) { const char* unit_escape_setting(const char *s, UnitWriteFlags flags, char **buf) { assert(s); - assert(!FLAGS_SET(flags, UNIT_ESCAPE_EXEC_SYNTAX_ENV | UNIT_ESCAPE_C)); + assert(popcount(flags & (UNIT_ESCAPE_EXEC_SYNTAX_ENV | UNIT_ESCAPE_EXEC_SYNTAX | UNIT_ESCAPE_C)) <= 1); assert(buf); _cleanup_free_ char *t = NULL; @@ -4334,15 +4335,17 @@ const char* unit_escape_setting(const char *s, UnitWriteFlags flags, char **buf) /* We either do C-escaping or shell-escaping, to additionally escape characters that we parse for * ExecStart= and friends, i.e. '$' and quotes. */ - if (flags & UNIT_ESCAPE_EXEC_SYNTAX_ENV) { + if (flags & (UNIT_ESCAPE_EXEC_SYNTAX_ENV | UNIT_ESCAPE_EXEC_SYNTAX)) { char *t2; - t2 = strreplace(s, "$", "$$"); - if (!t2) - return NULL; - free_and_replace(t, t2); + if (flags & UNIT_ESCAPE_EXEC_SYNTAX_ENV) { + t2 = strreplace(s, "$", "$$"); + if (!t2) + return NULL; + free_and_replace(t, t2); + } - t2 = shell_escape(t, "\""); + t2 = shell_escape(t ?: s, "\""); if (!t2) return NULL; free_and_replace(t, t2); |