diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 14bc8e52..946c89a9 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -54,12 +54,13 @@ All relevant changes are documented in this file. - Fix misspelled `SIGUNKOWN` returned by `sig_name()` for unknown signal numbers, now spelled correctly as `SIGUNKNOWN`. Surfaced by the new restart log above -- Fix mode of existing `d`/`D` directories in tmpfiles, the chmod branch - never ran because the directory creation swallowed `EEXIST`. Mode and - owner of `d`/`D`, `e`, and `f`/`F` entries, and of the directories - `mksubsys()` creates for the dbus plugin, 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 mode of existing `d`/`D` directories in tmpfiles when the entry + gives one, the chmod branch never ran because the directory creation + swallowed `EEXIST`. Mode and owner of `d`/`D`, `e`, and `f`/`F` + entries, and of the directories `mksubsys()` creates for the dbus + plugin, 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 crash at config load for a `stop:` or `reload:` script written with a timeout, e.g. `stop:5,/bin/true`, which took PID 1 down - Fix a lost reload for a service paused mid-reload by a condition in diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 55d2337a..b18c57f7 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -587,9 +587,7 @@ static void tmpfiles(char *line) if (gid < 0) gid = 0; - if (!mode) - mode = 0755; - rc = makedir(path, mode); + rc = makedir(path, mode ?: 0755); if (!rc && dirperm(path, mode, uid, gid)) warn("Failed setting mode/owner on %s", path); } diff --git a/test/Makefile.am b/test/Makefile.am index c34d4227..c230777c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -65,6 +65,7 @@ EXTRA_DIST += start-stop-sysv.sh EXTRA_DIST += start-stop-serv.sh EXTRA_DIST += signal-service.sh EXTRA_DIST += testserv.sh +EXTRA_DIST += tmpfiles-perm.sh EXTRA_DIST += unexpected-restart.sh AM_TESTS_ENVIRONMENT = SYSROOT='$(abs_builddir)/sysroot/'; @@ -115,6 +116,7 @@ TESTS += start-stop-serv.sh TESTS += signal-service.sh if TESTSERV TESTS += testserv.sh +TESTS += tmpfiles-perm.sh endif TESTS += unexpected-restart.sh diff --git a/test/tmpfiles-perm.sh b/test/tmpfiles-perm.sh new file mode 100755 index 00000000..60244c88 --- /dev/null +++ b/test/tmpfiles-perm.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Verify that tmpfiles leaves the mode of an existing directory alone +# when the entry does not give one, issue #523 +set -eu + +TEST_DIR=$(dirname "$0") + +DIR=/tmp/perm +CONF=/tmp/perm.conf + +# Run tmpfiles with entry $1, then check mode $2 and owner $3 of $DIR +assert_perm() +{ + run "echo '$1' > $CONF" + run "/libexec/finit/tmpfiles --create $CONF" + assert "Entry '$1' gives $2 $3" "$(texec stat -c '%a %U:%G' $DIR)" = "$2 $3" +} + +test_teardown() +{ + say "Running test teardown." + run "rm -rf $DIR $CONF" +} + +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + +sep +say 'A new directory gets the default mode and owner' +assert_perm "d $DIR" 755 root:root + +sep +say 'An existing directory keeps its mode when the entry gives none' +run "chmod 1777 $DIR" +assert_perm "d $DIR" 1777 root:root +assert_perm "d $DIR - - -" 1777 root:root +assert_perm "d $DIR 0750" 750 root:root +assert_perm "e $DIR" 750 root:root +assert_perm "d $DIR 1777 root root" 1777 root:root