From 7ee991daf2fef99465d7eef262d8a84f4fcd1937 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 20 Nov 2026 18:55:30 +0100 Subject: [PATCH] tmpfiles: make a new file 0644 when the f entry has no mode A file from an f entry without a mode got what the umask left of 0666, so the result depended on who called tmpfiles: f /run/app/state tmpfiles.d(5) has 0644 as the default. Use that for a file the entry creates. Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 2 ++ doc/tmpfiles-todo.md | 2 -- src/tmpfiles.c | 2 ++ test/tmpfiles-perm.sh | 5 +++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 68e67b2c..6132c5fe 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -301,6 +301,8 @@ All relevant changes are documented in this file. - Fix `tmpfiles --clean` for an `e` entry with a glob in the path, like `e /var/cache/* - - - 10d`, nothing was cleaned. The age of a `C` entry is now used as well +- Fix mode of a new file from a tmpfiles `f` entry without a mode, it is + now 0644 as in tmpfiles.d(5), before it followed the umask - Fix tmpfiles `w` entries with a glob that matches several paths, all but the first got the argument only up to its first backslash escape - Fix age `0` in a tmpfiles entry, it was read as no age. As in diff --git a/doc/tmpfiles-todo.md b/doc/tmpfiles-todo.md index 207f6832..93ba5a83 100644 --- a/doc/tmpfiles-todo.md +++ b/doc/tmpfiles-todo.md @@ -33,8 +33,6 @@ Missing options: `--root`, `--replace`, `--dry-run`, `--purge`, in `/etc` should run before `50-y.conf` in `/usr/lib` * `a` and `A` handle an ACL of at most 32 entries, a path with more is left as it is, with a warning -* A new `f` file without a mode gets what the umask leaves of 0666, - it should be 0644 * A `d` or `e` entry for a path that is a link to a directory warns that mode and owner could not be set * An `x` or `X` entry with an age should have what it names cleaned diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 0a35f35e..edb92aef 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -1653,6 +1653,8 @@ static void tmpfiles(char *line) write_arg(fp, arg); + if (strc && !perm.mode) + perm.mode = 0644; if (perm_set(fd, &perm, strc)) warn("Failed setting mode/owner on %s", path); diff --git a/test/tmpfiles-perm.sh b/test/tmpfiles-perm.sh index 6cd6ce9f..a93f5378 100755 --- a/test/tmpfiles-perm.sh +++ b/test/tmpfiles-perm.sh @@ -115,3 +115,8 @@ run "/libexec/finit/tmpfiles --create $CONF" assert "v" "$(texec stat -c '%F %a %U:%G' $DIR/v)" = "directory 750 bin:sys" assert "q" "$(texec stat -c '%F %a %U:%G' $DIR/q)" = "directory 700 sys:bin" assert "Q" "$(texec stat -c '%F %a %U:%G' $DIR/Q)" = "directory 755 root:root" + +sep +say 'A new file without a mode is 0644, whatever the umask' +run "echo 'f $DIR/default' > $CONF; umask 077; /libexec/finit/tmpfiles --create $CONF" +assert "Default mode" "$(texec stat -c '%a' $DIR/default)" = "644"