1
0
mirror of https://github.com/systemd/systemd synced 2025-09-28 00:04:47 +02:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Yu Watanabe
65ab27211c
Merge pull request #18225 from poettering/tmpfiles-argument
tmpfiles: fix documentation about quoting the "argument" field in tmpfiles.d snippets
2021-01-13 15:57:42 +09:00
Lennart Poettering
1cf96f68db test: add a test that ensures we don't regress on "argument" field handling in tmpfiles.d
Let's make sure what is now documented as fix for #17740 is not
accidentally changed anymore.
2021-01-12 22:00:35 +01:00
Lennart Poettering
3f532a5930 tmpfiles: add ANSI highlighting to our help text
As it is common now in our tools.
2021-01-12 22:00:35 +01:00
Lennart Poettering
fa67d9c0d6 extract-word: don't rely on C's downgrade-to-bool feature for chars
The `quote` char variable ectually contains a character, not a pointer
or boolean. hence do an explicit comparison rather than rely on C's
downgrade to bool feature, as per our coding style.
2021-01-12 22:00:35 +01:00
Lennart Poettering
29271da500 tmpfiles: document that the "argument" field doesn't do quotes
This adjust the documentation to match the code, addressing #17740.

I actually think that not making the "argument" field accept quotes was
a mistake, but I also understand why this choice was made. Given that we
shipped this forever like this though I don't think it's worth changing
the behaviour now. Supporting quotes for this is not that important I
guess. Hence document the current behaviour.

Fixes: #17740
2021-01-12 22:00:35 +01:00
4 changed files with 44 additions and 11 deletions

View File

@ -145,14 +145,17 @@ A+ /path-or-glob/to/append/acls/recursively - - - - POSIX
<refsect1>
<title>Configuration File Format</title>
<para>The configuration format is one line per path containing
type, path, mode, ownership, age, and argument fields:</para>
<para>The configuration format is one line per path, containing type, path, mode, ownership, age, and
argument fields. The lines are separated by newlines, the fields by whitespace:</para>
<programlisting>#Type Path Mode User Group Age Argument
<programlisting>#Type Path Mode User Group Age Argument
d /run/user 0755 root root 10d -
L /tmp/foobar - - - - /dev/null</programlisting>
<para>Fields may be enclosed within quotes and contain C-style escapes.</para>
<para>Fields may contain C-style escapes. With the exception of the seventh field (the "argument") all
fields may be enclosed in quotes. Note that any whitespace found in the line after the beginning of the
argument field will be considered part of the argument field. To begin the argument field with a
whitespace character, use C-style escapes (e.g. <literal>\x20</literal>).</para>
<refsect2>
<title>Type</title>

View File

@ -20,11 +20,10 @@
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags) {
_cleanup_free_ char *s = NULL;
size_t allocated = 0, sz = 0;
char c;
int r;
char quote = 0; /* 0 or ' or " */
bool backslash = false; /* whether we've just seen a backslash */
char c;
int r;
assert(p);
assert(ret);
@ -71,7 +70,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
if (c == 0) {
if ((flags & EXTRACT_CUNESCAPE_RELAX) &&
(!quote || flags & EXTRACT_RELAX)) {
(quote == 0 || flags & EXTRACT_RELAX)) {
/* If we find an unquoted trailing backslash and we're in
* EXTRACT_CUNESCAPE_RELAX mode, keep it verbatim in the
* output.
@ -116,7 +115,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
backslash = false;
} else if (quote) { /* inside either single or double quotes */
} else if (quote != 0) { /* inside either single or double quotes */
for (;; (*p)++, c = **p) {
if (c == 0) {
if (flags & EXTRACT_RELAX)

View File

@ -60,6 +60,7 @@
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "umask-util.h"
#include "user-util.h"
@ -2995,8 +2996,8 @@ static int help(void) {
if (r < 0)
return log_oom();
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
"Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n"
"\n%sCreates, deletes and cleans up volatile and temporary files and directories.%s\n\n"
" -h --help Show this help\n"
" --user Execute user configuration\n"
" --version Show package version\n"
@ -3014,6 +3015,7 @@ static int help(void) {
" --no-pager Do not pipe output into a pager\n"
"\nSee the %s for details.\n"
, program_invocation_short_name
, ansi_highlight(), ansi_normal()
, link
);

29
test/units/testsuite-22.10.sh Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e
set -x
set -o pipefail
systemd-tmpfiles --create - <<EOF
f /tmp/xxx1 0644 - - - foo
f /tmp/xxx2 0644 - - - foo bar
f /tmp/xxx3 0644 - - - foo\x20bar
f /tmp/xxx4 0644 - - - \x20foobar
f /tmp/xxx5 0644 - - - foobar\x20
f /tmp/xxx6 0644 - - - foo bar
f /tmp/xxx7 0644 - - - foo bar \n
f /tmp/xxx8 0644 - - - " foo bar "
f /tmp/xxx9 0644 - - - ' foo bar '
EOF
echo -n "foo" | cmp /tmp/xxx1 -
echo -n "foo bar" | cmp /tmp/xxx2 -
echo -n "foo bar" | cmp /tmp/xxx3 -
echo -n " foobar" | cmp /tmp/xxx4 -
echo -n "foobar " | cmp /tmp/xxx5 -
echo -n "foo bar" | cmp /tmp/xxx6 -
echo "foo bar " | cmp /tmp/xxx7 -
echo -n "\" foo bar \"" | cmp /tmp/xxx8 -
echo -n "' foo bar '" | cmp /tmp/xxx9 -
rm /tmp/xxx{1,2,3,4,5,6,7,8,9}