From 72923fa36d4250086b614c789928a13ededff23d Mon Sep 17 00:00:00 2001 From: Packit Bot Date: May 04 2021 22:13:44 +0000 Subject: Apply patch autofs-5.1.7-simplify-get_parent.patch patch_name: autofs-5.1.7-simplify-get_parent.patch present_in_specfile: true --- diff --git a/CHANGELOG b/CHANGELOG index 0ea7bde..40fd9e1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ - fix mnts_remove_amdmount() uses wrong list. - eliminate cache_lookup_offset() usage. - fix is mounted check on non existent path. +- simplify cache_get_parent(). xx/xx/2018 autofs-5.1.5 - fix flag file permission. diff --git a/lib/cache.c b/lib/cache.c index 44e323d..201ce20 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -797,47 +797,57 @@ void cache_update_negative(struct mapent_cache *mc, } -static struct mapent *get_parent(const char *key, struct list_head *head, struct list_head **pos) +static struct mapent *get_offset_parent(struct mapent_cache *mc, + const char *key) { - struct list_head *next; - struct mapent *this, *last; - int eq; + struct mapent *me; + char *parent, *tail; + int key_len; - last = NULL; - next = *pos ? (*pos)->next : head->next; + key_len = strlen(key); - list_for_each(next, head) { - this = list_entry(next, struct mapent, multi_list); + /* Check if this is the root offset */ + if (key[key_len - 1] == '/') + return NULL; + + parent = strdup(key); + tail = &parent[key_len - 1]; - if (!strcmp(this->key, key)) + while (*tail) { + while (*tail != '/') + tail--; + + *tail = 0; + + tail--; + if (tail == parent) break; - eq = strncmp(this->key, key, strlen(this->key)); - if (eq == 0) { - *pos = next; - last = this; - continue; + me = cache_lookup_distinct(mc, parent); + if (me) { + free(parent); + return me; } } + free(parent); - return last; + return NULL; } int cache_set_parents(struct mapent *mm) { - struct list_head *multi_head, *p, *pos; + struct list_head *multi_head, *p; struct mapent *this; if (!mm->multi) return 0; - pos = NULL; multi_head = &mm->multi->multi_list; list_for_each(p, multi_head) { struct mapent *parent; this = list_entry(p, struct mapent, multi_list); - parent = get_parent(this->key, multi_head, &pos); + parent = get_offset_parent(mm->mc, this->key); if (parent) this->parent = parent; else