diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 615ca8ec..45c6b49a 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -259,6 +259,8 @@ All relevant changes are documented in this file. - Fix tmpfiles giving up at the first entry it does not support, an unknown type or a `%` specifier in the path. No entry after it was run, in that file or in the files after it. Such an entry is now skipped with a warning +- Fix `tmpfiles --clean` cleaning other file systems mounted below the + directory of an entry, it now stays on the file system of the directory - 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 diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 8e1f885d..46cbdc17 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -831,7 +831,7 @@ static void tmpfiles(char *line) break; clean_age = max_age; clean_now = time(NULL); - nftw(path, do_clean, 20, FTW_DEPTH | FTW_PHYS); + nftw(path, do_clean, 20, FTW_DEPTH | FTW_PHYS | FTW_MOUNT); break; case 'x': case 'X': diff --git a/test/Makefile.am b/test/Makefile.am index 435d6587..a1a1f66a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -85,6 +85,7 @@ EXTRA_DIST += tmpfiles-acl.sh EXTRA_DIST += tmpfiles-arg.sh EXTRA_DIST += tmpfiles-perm.sh EXTRA_DIST += tmpfiles-boot.sh +EXTRA_DIST += tmpfiles-clean.sh EXTRA_DIST += tmpfiles-order.sh EXTRA_DIST += tmpfiles-unsupported.sh EXTRA_DIST += unexpected-restart.sh @@ -168,6 +169,7 @@ TESTS += tmpfiles-acl.sh TESTS += tmpfiles-arg.sh TESTS += tmpfiles-perm.sh TESTS += tmpfiles-boot.sh +TESTS += tmpfiles-clean.sh TESTS += tmpfiles-order.sh TESTS += tmpfiles-unsupported.sh endif diff --git a/test/tmpfiles-clean.sh b/test/tmpfiles-clean.sh new file mode 100755 index 00000000..12cbdc5e --- /dev/null +++ b/test/tmpfiles-clean.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Verify tmpfiles --clean, removing what is older than the age of an entry +set -eu + +TEST_DIR=$(dirname "$0") + +DIR=/tmp/clean +CONF=/tmp/clean.conf + +clean() +{ + run "cat > $CONF" + run "/libexec/finit/tmpfiles --clean $CONF" +} + +assert_left() +{ + assert "Left in $1: $2" "$(texec ls "$1" | tr '\n' ' ')" = "$2" +} + +test_teardown() +{ + say "Running test teardown." + run "umount $DIR/old/mnt 2>/dev/null; rm -rf $DIR $CONF" +} + +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + +run "mkdir -p $DIR/old/mnt $DIR/old/sub $DIR/young; touch $DIR/old/file $DIR/old/sub/file $DIR/young/file" +run "mount -t tmpfs none $DIR/old/mnt; touch $DIR/old/mnt/file" +sleep 2 + +sep +say 'Only what is older than the age is removed, and nothing on another file system' +clean <