Merge pull request #15345 from keszybz/systemctl-show-spaces

Show Environment= entries with spaces in systemctl
This commit is contained in:
Lennart Poettering
2020-04-09 13:55:35 +02:00
committed by GitHub
4 changed files with 42 additions and 17 deletions
+12 -6
View File
@@ -518,22 +518,28 @@ char* shell_maybe_quote(const char *s, EscapeStyle style) {
return NULL;
t = r;
if (style == ESCAPE_BACKSLASH)
switch (style) {
case ESCAPE_BACKSLASH:
case ESCAPE_BACKSLASH_ONELINE:
*(t++) = '"';
else if (style == ESCAPE_POSIX) {
break;
case ESCAPE_POSIX:
*(t++) = '$';
*(t++) = '\'';
} else
break;
default:
assert_not_reached("Bad EscapeStyle");
}
t = mempcpy(t, s, p - s);
if (style == ESCAPE_BACKSLASH)
t = strcpy_backslash_escaped(t, p, SHELL_NEED_ESCAPE, false);
if (IN_SET(style, ESCAPE_BACKSLASH, ESCAPE_BACKSLASH_ONELINE))
t = strcpy_backslash_escaped(t, p, SHELL_NEED_ESCAPE,
style == ESCAPE_BACKSLASH_ONELINE);
else
t = strcpy_backslash_escaped(t, p, SHELL_NEED_ESCAPE_POSIX, true);
if (style == ESCAPE_BACKSLASH)
if (IN_SET(style, ESCAPE_BACKSLASH, ESCAPE_BACKSLASH_ONELINE))
*(t++) = '"';
else
*(t++) = '\'';
+7 -2
View File
@@ -34,8 +34,13 @@ typedef enum UnescapeFlags {
} UnescapeFlags;
typedef enum EscapeStyle {
ESCAPE_BACKSLASH = 1,
ESCAPE_POSIX = 2,
ESCAPE_BACKSLASH = 1, /* Add shell quotes ("") so the shell will consider this a single
argument, possibly multiline. Tabs and newlines are not escaped. */
ESCAPE_BACKSLASH_ONELINE = 2, /* Similar to ESCAPE_BACKSLASH, but always produces a single-line
string instead. Shell escape sequences are produced for tabs and
newlines. */
ESCAPE_POSIX = 3, /* Similar to ESCAPE_BACKSLASH_ONELINE, but uses POSIX shell escape
* syntax (a string enclosed in $'') instead of plain quotes. */
} EscapeStyle;
char *cescape(const char *s);