tmpfiles: only take a # at the start of a line as a comment

An entry with a # in the argument loses it and the rest of the line:

    f /tmp/file - - - - a#b c

gives a file holding "a".  The lines are read with fparseln(), which
by default takes a # anywhere in a line as the start of a comment.  In
tmpfiles.d(5) only a line that starts with # is a comment.

Read the lines without a comment character and skip the lines that
start with one.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 17:13:53 +01:00
1 parent 7ec4376eb0
commit 309844fc11
3 files changed
+13 -3

No files matched your search

+4
View File
@@ -317,6 +317,10 @@ All relevant changes are documented in this file.
entry entry
- Fix `\x` escapes with the digits 8 or 9 in the argument of a tmpfiles - Fix `\x` escapes with the digits 8 or 9 in the argument of a tmpfiles
entry, `\x39` was written as the byte 3 and a `9` entry, `\x39` was written as the byte 3 and a `9`
- Fix a `#` in the argument of a tmpfiles entry, it and the rest of the
line were dropped as a comment. As in tmpfiles.d(5), only a line that
starts with `#` is a comment. **Note:** a comment at the end of an
entry is now read as its argument
- Fix logins refused after boot on a system with systemd's tmpfiles.d - Fix logins refused after boot on a system with systemd's tmpfiles.d
files installed. They create `/run/nologin` at boot, and on systemd it files installed. They create `/run/nologin` at boot, and on systemd it
is removed by systemd-user-sessions. Finit now removes it when leaving is removed by systemd-user-sessions. Finit now removes it when leaving
+4 -2
View File
@@ -1374,7 +1374,7 @@ static void tmpfiles(char *line)
glob_t gl; glob_t gl;
type = strtok(line, "\t "); type = strtok(line, "\t ");
if (!type) if (!type || type[0] == '#')
return; return;
for (char *mod = &type[1]; *mod; mod++) { for (char *mod = &type[1]; *mod; mod++) {
@@ -1821,9 +1821,11 @@ static void process_file(const char *fn)
} }
while (!feof(fp)) { while (!feof(fp)) {
/* No comment character, a # is only a comment at the start of a line */
const char delim[3] = { '\\', '\\', 0 };
char *line; char *line;
line = fparseln(fp, NULL, NULL, NULL, FPARSELN_UNESCCOMM); line = fparseln(fp, NULL, NULL, delim, 0);
if (!line) if (!line)
continue; continue;
+5 -1
View File
@@ -66,9 +66,13 @@ assert "First match" "$(texec cat $DIR/w1 | tr '\n' ' ')" = "one two"
assert "Second match" "$(texec cat $DIR/w2 | tr '\n' ' ')" = "one two" assert "Second match" "$(texec cat $DIR/w2 | tr '\n' ' ')" = "one two"
sep sep
say 'Escapes in the argument' say 'Escapes, and a # that is not at the start of the line'
run "cat > $CONF" <<'CONF' run "cat > $CONF" <<'CONF'
# A comment
# and one more
f /tmp/arg/hex - - - - \x39\x41\x4a\x6b f /tmp/arg/hex - - - - \x39\x41\x4a\x6b
f /tmp/arg/hash - - - - a#b c
CONF CONF
run "/libexec/finit/tmpfiles --create $CONF" run "/libexec/finit/tmpfiles --create $CONF"
assert "All hex digits" "$(texec cat $DIR/hex)" = "9AJk" assert "All hex digits" "$(texec cat $DIR/hex)" = "9AJk"
assert "No comment in line" "$(texec cat $DIR/hash)" = "a#b c"