tmpfiles: keep the owner of an existing path when none is given

An entry without a user or group, or with "-", made root the owner of
an existing directory or file:

    mkdir -p /tmp/t && chown daemon:daemon /tmp/t
    echo 'd /tmp/t' > t.conf
    tmpfiles --create t.conf
    stat -c %U:%G /tmp/t

This gave root:root.  A missing field was read as "root" when parsing
the entry, the same as if it had been written out.  tmpfiles.d(5)
only adjusts the owner when the entry gives one.

A missing user or group is now -1, and fdperm() looks at the two ids
separately, so "d /tmp/t - - sys" changes the group and keeps the
owner.  mksubsys() and the service directories used uid -1 to skip
the chown altogether, they now pass -1 for the group as well.

Issue #523

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-20 11:23:36 +01:00
1 parent 94bdccd200
commit f95db7e6df
5 files changed
+41 -35

No files matched your search

+3
View File
@@ -240,6 +240,9 @@ All relevant changes are documented in this file.
`mksubsysd()` creates, are now set through an open fd and only when they
differ, so an immutable directory like `/var/empty` no longer warns on every
boot. By Sam Brkopac
- Fix owner of existing directories and files in tmpfiles, an entry with no
user or group, or `-`, reset them to `root`. As in tmpfiles.d(5), the
owner and the group are now each left alone unless the entry gives them
- Fix a lost reload for a service paused mid-reload by a condition in
flux. A second reload arriving meanwhile re-parsed the unchanged .conf
and cleared the pending mark, so the service resumed without ever being