From: Yu Watanabe Date: Sun, 11 Apr 2021 07:46:25 +0000 (+0900) Subject: Merge pull request #19164 from mmatsuya/main X-Git-Tag: v249-rc1~434 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37b7a716d3ea29bc9286c21c55b84a6264148ccd;hp=a7b7cab66df8c0a701bc6da3a309fa80c90a880b;p=thirdparty%2Fsystemd.git Merge pull request #19164 from mmatsuya/main tmpfiles: use a entry in hashmap as ItemArray in read_config_file() --- diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml index 55b763e26d5..35b762ca3f7 100644 --- a/man/tmpfiles.d.xml +++ b/man/tmpfiles.d.xml @@ -58,8 +58,8 @@ c+ /dev/char-device-to-[re]create mode user group - major b /dev/block-device-to-create mode user group - major:minor b+ /dev/block-device-to-[re]create mode user group - major:minor C /target/to/create - - - - /source/to/copy -x /path-or-glob/to/ignore - - - - - -X /path-or-glob/to/ignore/recursively - - - - - +x /path-or-glob/to/ignore/recursively - - - - - +X /path-or-glob/to/ignore - - - - - r /empty/dir/to/remove - - - - - R /dir/to/remove/recursively - - - - - z /path-or-glob/to/adjust/mode mode user group - - diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 6b26dc8b9c3..b6de1e74b21 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -3187,7 +3187,7 @@ static int read_config_file(char **config_dirs, const char *fn, bool ignore_enoe _cleanup_fclose_ FILE *_f = NULL; unsigned v = 0; FILE *f; - Item *i; + ItemArray *ia; int r = 0; assert(fn); @@ -3240,31 +3240,41 @@ static int read_config_file(char **config_dirs, const char *fn, bool ignore_enoe } /* we have to determine age parameter for each entry of type X */ - ORDERED_HASHMAP_FOREACH(i, globs) { - Item *j, *candidate_item = NULL; + ORDERED_HASHMAP_FOREACH(ia, globs) + for (size_t ni = 0; ni < ia->n_items; ni++) { + ItemArray *ja; + Item *i = ia->items + ni, *candidate_item = NULL; - if (i->type != IGNORE_DIRECTORY_PATH) - continue; - - ORDERED_HASHMAP_FOREACH(j, items) { - if (!IN_SET(j->type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)) + if (i->type != IGNORE_DIRECTORY_PATH) continue; - if (path_equal(j->path, i->path)) { - candidate_item = j; - break; - } + ORDERED_HASHMAP_FOREACH(ja, items) + for (size_t nj = 0; nj < ja->n_items; nj++) { + Item *j = ja->items + nj; - if ((!candidate_item && path_startswith(i->path, j->path)) || - (candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0))) - candidate_item = j; - } + if (!IN_SET(j->type, CREATE_DIRECTORY, + TRUNCATE_DIRECTORY, + CREATE_SUBVOLUME, + CREATE_SUBVOLUME_INHERIT_QUOTA, + CREATE_SUBVOLUME_NEW_QUOTA)) + continue; - if (candidate_item && candidate_item->age_set) { - i->age = candidate_item->age; - i->age_set = true; + if (path_equal(j->path, i->path)) { + candidate_item = j; + break; + } + + if (candidate_item + ? (path_startswith(j->path, candidate_item->path) && fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0) + : path_startswith(i->path, j->path) != NULL) + candidate_item = j; + } + + if (candidate_item && candidate_item->age_set) { + i->age = candidate_item->age; + i->age_set = true; + } } - } if (ferror(f)) { log_error_errno(errno, "Failed to read from file %s: %m", fn); diff --git a/test/units/testsuite-22.11.sh b/test/units/testsuite-22.11.sh new file mode 100755 index 00000000000..21ef210cd16 --- /dev/null +++ b/test/units/testsuite-22.11.sh @@ -0,0 +1,141 @@ +#! /bin/bash + +set -e +set -x + +rm -fr /tmp/x +mkdir /tmp/x + +# +# 'x' +# +mkdir -p /tmp/x/{1,2} +touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2} + +systemd-tmpfiles --clean - <