tmpfiles: set mode and owner for the entries that ignored them

Several types read the mode and owner of an entry and did nothing
with them.  An f entry was skipped when the file was there:

    f /var/log/app.log 0640 app adm

This left a file with another mode or owner as it was.  The owner of
p, b, and c entries was never set, and their mode was cut by the
umask.  C, z, and Z entries had neither applied.

Set them for all of these, Z for everything below the path.  Fifos
and device nodes are opened with O_PATH, so nothing is opened for
real.  A path that is not what the entry makes, like a directory
where a p entry wants a fifo, is left alone.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-20 18:03:30 +01:00
1 parent ec67ecc805
commit adf7080fca
4 files changed
+107 -37

No files matched your search

+27
View File
@@ -63,3 +63,30 @@ say 'With ~ the mode loses what no one has on the path'
run "chmod 500 $DIR"
assert_perm "e $DIR ~0777" 555 bin:bin
assert_perm "e $DIR :~0700 :sys" 555 bin:bin
sep
say 'Mode and owner of an f entry are set on an existing file too'
run "echo keep > $DIR/file; chmod 600 $DIR/file"
run "echo 'f $DIR/file 0644 bin sys - new' > $CONF; /libexec/finit/tmpfiles --create $CONF"
assert "Mode and owner" "$(texec stat -c '%a %U:%G' $DIR/file)" = "644 bin:sys"
assert "Content is kept" "$(texec cat $DIR/file)" = "keep"
sep
say 'Mode and owner of p, C, z, and Z entries'
run "mkdir -p $DIR/tree/sub; touch $DIR/tree/sub/file"
run "cat > $CONF" <<CONF
p $DIR/fifo 0660 bin sys
C $DIR/copy 0600 bin sys - /etc/group
z $DIR/file 0600 sys bin
Z $DIR/tree - bin sys
CONF
run "umask 077; /libexec/finit/tmpfiles --create $CONF"
assert "p" "$(texec stat -c '%a %U:%G' $DIR/fifo)" = "660 bin:sys"
assert "C" "$(texec stat -c '%a %U:%G' $DIR/copy)" = "600 bin:sys"
assert "z" "$(texec stat -c '%a %U:%G' $DIR/file)" = "600 sys:bin"
assert "Z" "$(texec stat -c '%U:%G' $DIR/tree/sub/file)" = "bin:sys"
sep
say 'A p entry leaves a path that is not a fifo alone'
run "echo 'p $DIR/file 0644 root root' > $CONF; /libexec/finit/tmpfiles --create $CONF"
assert "Not a fifo" "$(texec stat -c '%a %U:%G' $DIR/file)" = "600 sys:bin"