From: dongshengyuan <545258830@qq.com> Date: Wed, 15 Jul 2026 05:35:57 +0000 (+0800) Subject: tmpfiles: inherit age-by for X entries X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cc7ccc02ccef09c0c751287176e0006dbe205a1;p=thirdparty%2Fsystemd.git tmpfiles: inherit age-by for X entries X entries inherit the cleanup age from the closest parent directory rule. Inherit the age-by fields too, so parent rules such as m:1d keep their full cleanup policy. Reproducer: mkdir -p /tmp/tmpfiles-ageby/parent/{child,other} printf old >/tmp/tmpfiles-ageby/parent/child/file printf old >/tmp/tmpfiles-ageby/parent/other/file touch -d '3 days ago' /tmp/tmpfiles-ageby/parent/{child,other}/file systemd-tmpfiles --clean - <<'EOT' d /tmp/tmpfiles-ageby/parent - - - m:1d X /tmp/tmpfiles-ageby/parent/child - - - - EOT Before: child/file remained because X used the default age-by set. other/file was removed by the parent m: rule. Follow-up for 7f7a50dd157b3bfb4282c3cc3a56671121eabe24. --- diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 72781a49b72..464384b22bd 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -4720,6 +4720,8 @@ static int read_config_file( if (candidate_item && candidate_item->age_set) { i->age = candidate_item->age; i->age_set = true; + i->age_by_file = candidate_item->age_by_file; + i->age_by_dir = candidate_item->age_by_dir; } } diff --git a/test/units/TEST-22-TMPFILES.12.sh b/test/units/TEST-22-TMPFILES.12.sh index 1aa4faa0d38..b2288bcf016 100755 --- a/test/units/TEST-22-TMPFILES.12.sh +++ b/test/units/TEST-22-TMPFILES.12.sh @@ -219,3 +219,19 @@ after="$(stat -c %Y /tmp/ageby-mtime)" test "$before" = "$after" test ! -e /tmp/ageby-mtime/old-child rmdir /tmp/ageby-mtime + +# X entries inherit the parent cleanup age and its age-by fields. +rm -rf /tmp/ageby-x-inherit +mkdir -p /tmp/ageby-x-inherit/parent/child /tmp/ageby-x-inherit/parent/other +printf old >/tmp/ageby-x-inherit/parent/child/file +printf old >/tmp/ageby-x-inherit/parent/other/file +touch --date "3 days ago" /tmp/ageby-x-inherit/parent/child/file /tmp/ageby-x-inherit/parent/other/file + +systemd-tmpfiles --clean - <<-EOF +d /tmp/ageby-x-inherit/parent - - - m:1d +X /tmp/ageby-x-inherit/parent/child - - - - +EOF + +test ! -e /tmp/ageby-x-inherit/parent/child/file +test ! -e /tmp/ageby-x-inherit/parent/other/file +rm -rf /tmp/ageby-x-inherit