Merge pull request #18225 from poettering/tmpfiles-argument

tmpfiles: fix documentation about quoting the "argument" field in tmpfiles.d snippets
This commit is contained in:
Yu Watanabe 2021-01-13 15:57:42 +09:00 committed by GitHub
commit 65ab27211c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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}