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 -2
View File
@@ -1374,7 +1374,7 @@ static void tmpfiles(char *line)
glob_t gl;
type = strtok(line, "\t ");
if (!type)
if (!type || type[0] == '#')
return;
for (char *mod = &type[1]; *mod; mod++) {
@@ -1821,9 +1821,11 @@ static void process_file(const char *fn)
}
while (!feof(fp)) {
/* No comment character, a # is only a comment at the start of a line */
const char delim[3] = { '\\', '\\', 0 };
char *line;
line = fparseln(fp, NULL, NULL, NULL, FPARSELN_UNESCCOMM);
line = fparseln(fp, NULL, NULL, delim, 0);
if (!line)
continue;