Bug 1944468

Summary: No difference between x and X type in systemd-tmpfiles
Product: Red Hat Enterprise Linux 8 Reporter: Masahiro Matsuya <mmatsuya>
Component: systemdAssignee: David Tardon <dtardon>
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.4CC: dtardon, systemd-maint-list, xnie
Target Milestone: rcKeywords: Bugfix, Reproducer, Triaged
Target Release: 8.5   
Hardware: x86_64   
OS: All   
Whiteboard:
Fixed In Version: systemd-239-57.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-10 15:25:47 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Masahiro Matsuya 2021-03-30 01:48:29 UTC
Description of problem:

Even with the 'X' type, the content in the specified directory are excluded.
From "man tmpfiles.d":

       X
           Ignore a path during cleaning. Use this type to exclude paths from clean-up as controlled with the Age parameter. 
           Unlike x, this parameter will not exclude the content if path is a directory, but only directory itself. Note that 
           lines of this type do not influence the effect of r or R lines. Lines of this type accept shell-style globs in 
           place of normal path names.

This was caused by the wrong usage of hashmap in read_config_file() of src/tmpfiles/tmpfiles.c.
This entry of this hashmap is ItemArray, but it is dealt with as Item.


static int read_config_file(char **config_dirs, const char *fn, bool ignore_enoent, bool *invalid_config) {

        Item *i;
...
        /* we have to determine age parameter for each entry of type X */
        ORDERED_HASHMAP_FOREACH(i, globs, iterator) {          <<======  This 'i' should be the variable of ItemArray structure.
                Iterator iter;
                Item *j, *candidate_item = NULL;

                if (i->type != IGNORE_DIRECTORY_PATH)          <<====== [A]
                        continue;

                ORDERED_HASHMAP_FOREACH(j, items, iter) {      <<======  This 'j' should be the variable of ItemArray structure.
                        if (!IN_SET(j->type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA))


As a result, the condition in above [A] is *always* TRUE, even when the type is 'X' (IGNORE_DIRECTORY_PATH).
I created a proposed patch, and confirmed that it worked as expected.


Version-Release number of selected component (if applicable):

RHEL 8.3


How reproducible:

Always

Steps to Reproduce:

1. create /etc/tmpfiles.d/test.conf

  # cat /etc/tmpfiles.d/test.conf
  X /root/test/tmp
  d /root/test - - - 0 

2. make a directory and the contents for testing.

  # mkdir -p ~/test/{tmp,tmp2}; touch ~/test/tmp/{x1,x2} ~/test/tmp2/{y1,y2} ~/test/{z1,z2}

3. Run systemd-tmpfiles

  # systemd-tmpfiles --clean test.conf


Actual results:

The contents in the specified directory with 'X' type were excluded.

  # tree ~/test
  /root/test
  └── tmp
      ├── x1
      └── x2

Expected results:

The contents in the specified directory with 'X' type were not excluded for cleanup.

  # tree ~/test
  /root/test
  └── tmp


Additional info:

It seems that the upstream has the same bug.
  https://github.com/systemd/systemd/blob/main/src/tmpfiles/tmpfiles.c

Comment 8 Plumber Bot 2021-08-31 08:24:20 UTC
fix merged to github master branch -> https://github.com/redhat-plumbers/systemd-rhel8/pull/170

Comment 12 Plumber Bot 2022-01-24 13:40:51 UTC
fix merged to github master branch -> https://github.com/redhat-plumbers/systemd-rhel8/pull/212

Comment 17 errata-xmlrpc 2022-05-10 15:25:47 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (systemd bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:2069