tmpfiles: read quotes and escapes in the fields before the argument

There is no way to write an entry for a path with a space in it, the
fields are split at every space.  In tmpfiles.d(5) a field can be
quoted, and have C-style escapes:

    d "/srv/my files"
    d /srv/my\sfiles

Split the fields with a function that resolves both.  The argument is
still the rest of the line as it is, quotes and all, like in systemd.
An entry with a quote left open is skipped.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 17:14:01 +01:00
1 parent aa38c72044
commit ed96814fdc
4 files changed
+92 -13

No files matched your search

+16
View File
@@ -86,3 +86,19 @@ CONF
run "/libexec/finit/tmpfiles --create $CONF"
assert "All hex digits" "$(texec cat $DIR/hex)" = "9AJk"
assert "No comment in line" "$(texec cat $DIR/hash)" = "a#b c"
sep
say 'A path can be quoted, and have escapes'
run "cat > $CONF" <<'CONF'
f "/tmp/arg/with space" - - - - double
f '/tmp/arg/single quote' - - - - single
f /tmp/arg/mid"dle sp"ace - - - - middle
f /tmp/arg/esc\x41\sped - - - - "kept as is"
f "/tmp/arg/open - - - - quote
CONF
run "/libexec/finit/tmpfiles --create $CONF"
assert "Double quotes" "$(texec cat "$DIR/with space")" = "double"
assert "Single quotes" "$(texec cat "$DIR/single quote")" = "single"
assert "Quotes in path" "$(texec cat "$DIR/middle space")" = "middle"
assert "Escapes in path" "$(texec cat "$DIR/escA ped")" = '"kept as is"'
assert "Skipped with a quote left open" "$(texec sh -c "ls $DIR | grep -c open")" = "0"