From 29271da500e7bbd818843036a05229c42cf7b640 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Jan 2021 21:34:50 +0100 Subject: [PATCH 1/4] 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 --- man/tmpfiles.d.xml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml index 49ce8375a4..4adbf6bb0a 100644 --- a/man/tmpfiles.d.xml +++ b/man/tmpfiles.d.xml @@ -145,14 +145,17 @@ A+ /path-or-glob/to/append/acls/recursively - - - - POSIX Configuration File Format - The configuration format is one line per path containing - type, path, mode, ownership, age, and argument fields: + 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: - #Type Path Mode User Group Age Argument + #Type Path Mode User Group Age Argument… d /run/user 0755 root root 10d - L /tmp/foobar - - - - /dev/null - Fields may be enclosed within quotes and contain C-style escapes. + 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. \x20). Type From fa67d9c0d652dc41574b546f542909e9c8157237 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Jan 2021 21:36:54 +0100 Subject: [PATCH 2/4] 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. --- src/basic/extract-word.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index 76b3fe12e3..4104dac9a7 100644 --- a/src/basic/extract-word.c +++ b/src/basic/extract-word.c @@ -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) From 3f532a593093a5ae2889f862d058521e74fa254e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Jan 2021 21:38:04 +0100 Subject: [PATCH 3/4] tmpfiles: add ANSI highlighting to our help text As it is common now in our tools. --- src/tmpfiles/tmpfiles.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 4ebdaddb5b..955cf00ce4 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -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 ); From 1cf96f68dbb90923f193b5f501ebab3780001efd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Jan 2021 21:39:02 +0100 Subject: [PATCH 4/4] 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. --- test/units/testsuite-22.10.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 test/units/testsuite-22.10.sh diff --git a/test/units/testsuite-22.10.sh b/test/units/testsuite-22.10.sh new file mode 100755 index 0000000000..5ec297fbf8 --- /dev/null +++ b/test/units/testsuite-22.10.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -e +set -x +set -o pipefail + +systemd-tmpfiles --create - <