Flip traversal order for llist iterate/list operations
This patch flips the order for the linked list traversal in iterate()/list().
This is an implementation fix, which makes ports added later take precedence over ports added earlier. That's because ports are added to the policydb in the iterate() order.
I'm not quite happy with this - I want the property above to be guaranteed in the specification of add() - things added later should take precedence over things added earlier (if ordering is a factor). To do that, I want the specification for iterate()/list() to guarantee traversal in the order things were added in (which is something that you'd usually expect iterate() to do). This is now true for anything backed in a file. It's also true for libsepol users. It's true trivially for libsepol booleans, because you can't add new libsepol booleans. However, it is *not* true for libsepol interfaces, and ports, where the list is traversed backwards. There iterate() works exactly the opposite way. It's a singly linked list, unfortunately. (the ocontext list..)
libsemanage/src/database_llist.c +2 -2
@@ -237,7 +237,7 @@ hidden int dbase_llist_iterate(int rc;cache_entry_t * ptr; -for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) { +for (ptr = dbase->cache_tail; ptr !=NULL ; ptr = ptr->prev) { rc =fn (ptr->data, arg);if (rc <0 )
@@ -307,7 +307,7 @@ hidden int dbase_llist_list(if (tmp_records ==NULL ) goto omem; -for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) { +for (ptr = dbase->cache_tail; ptr !=NULL ; ptr = ptr->prev) {if (dbase->rtable->clone (handle, ptr->data, &tmp_records[i]) <0 ) goto err;