tmpfiles: read the files by name, the first entry for a path counts

The files were read one directory at a time, Finit's own first and
/etc/tmpfiles.d last, and every entry for a path was run.  With two
entries for a path the last one read won, so an entry in /etc won over
one in /usr/lib whatever the files were called.

tmpfiles.d(5) reads the files in the order of their names, whatever
directory they are in, and goes by the first entry that makes a path.
A package relies on that when it names its file to sort before or
after another.  Do the same.  As before, a file in a later directory
is read in place of one of the same name in an earlier one.

A later entry is skipped when it makes a path an earlier one makes, or
when both take a glob and remove, write to, or keep the path.  Several
w+ entries may add to one file.  The skip is only told about with
--dry-run or --debug, since Finit's files and those of other packages
overlap on most systems.

Finit's own files had two entries for some paths, and relied on the
last one.  Drop the ones that lost: /run/lock, /run/lock/subsys, and
/var/lock in legacy.conf, and /var/run and a second /var/spool in
var.conf.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 19:23:49 +01:00
1 parent 86bb79d7a1
commit dd186287d7
9 files changed
+152 -50

No files matched your search

+2
View File
@@ -88,6 +88,7 @@ EXTRA_DIST += tmpfiles-perm.sh
EXTRA_DIST += tmpfiles-boot.sh
EXTRA_DIST += tmpfiles-clean.sh
EXTRA_DIST += tmpfiles-copy.sh
EXTRA_DIST += tmpfiles-files.sh
EXTRA_DIST += tmpfiles-match.sh
EXTRA_DIST += tmpfiles-order.sh
EXTRA_DIST += tmpfiles-specifier.sh
@@ -176,6 +177,7 @@ TESTS += tmpfiles-perm.sh
TESTS += tmpfiles-boot.sh
TESTS += tmpfiles-clean.sh
TESTS += tmpfiles-copy.sh
TESTS += tmpfiles-files.sh
TESTS += tmpfiles-match.sh
TESTS += tmpfiles-order.sh
TESTS += tmpfiles-specifier.sh
+2 -1
View File
@@ -71,9 +71,10 @@ run "printf abcdef > $DIR/w1"
run "cat > $CONF" <<'CONF'
w /tmp/arg/w1 - - - - XY
w+ /tmp/arg/w1 - - - - Z
w+ /tmp/arg/w1 - - - - Z
CONF
run "/libexec/finit/tmpfiles --create $CONF"
assert "Written in place" "$(texec cat $DIR/w1)" = "XYcdefZ"
assert "Written in place, added to by each w+" "$(texec cat $DIR/w1)" = "XYcdefZZ"
sep
say 'Escapes, and a # that is not at the start of the line'
+47
View File
@@ -0,0 +1,47 @@
#!/bin/sh
# Verify which tmpfiles.d files are read, in what order, and that the
# first entry for a path is the one that counts
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/files
LIB=/usr/lib/tmpfiles.d
ETC=/etc/tmpfiles.d
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $LIB/[0-9]0-test.conf $ETC/[0-9]0-test.conf"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
run "mkdir -p $LIB $ETC"
run "cat > $LIB/50-test.conf" <<CONF
f $DIR/same - - - - lib
f $DIR/masked - - - - lib
CONF
run "cat > $ETC/50-test.conf" <<CONF
f $DIR/same - - - - etc
CONF
run "cat > $LIB/10-test.conf" <<CONF
f $DIR/first - - - - one
CONF
run "cat > $ETC/20-test.conf" <<CONF
f $DIR/first - - - - two
w+ $DIR/first - - - - +three
w+ $DIR/first - - - - +four
CONF
run "/libexec/finit/tmpfiles --create --prefix=$DIR"
say 'A file in /etc is read in place of one of the same name in /usr/lib'
assert "Entry from /etc" "$(texec cat $DIR/same)" = "etc"
assert "None from /usr/lib" "$(texec sh -c "ls $DIR | grep -c masked")" = "0"
sep
say 'Files are read by name, and the first entry for a path counts'
assert "First by file name" "$(texec cat $DIR/first)" = "one+three+four"
assert "Told about in a dry run" \
"$(texec sh -c "/libexec/finit/tmpfiles -n --create --prefix=$DIR 2>&1 | grep -c 'already has an entry'")" = "1"