libvirt/src/security
Michal Privoznik cfcbba4c2b lib: Replace qsort() with g_qsort_with_data()
While glibc provides qsort(), which usually is just a mergesort,
until sorting arrays so huge that temporary array used by
mergesort would not fit into physical memory (which in our case
is never), we are not guaranteed it'll use mergesort. The
advantage of mergesort is clear - it's stable. IOW, if we have an
array of values parsed from XML, qsort() it and produce some
output based on those values, we can then compare the output with
some expected output, line by line.

But with newer glibc this is all history. After [1], qsort() is
no longer mergesort but introsort instead, which is not stable.
This is suboptimal, because in some cases we want to preserve
order of equal items. For instance, in ebiptablesApplyNewRules(),
nwfilter rules are sorted by their priority. But if two rules
have the same priority, we want to keep them in the order they
appear in the XML. Since it's hard/needless work to identify
places where stable or unstable sorting is needed, let's just
play it safe and use stable sorting everywhere.

Fortunately, glib provides g_qsort_with_data() which indeed
implement mergesort and it's a drop in replacement for qsort(),
almost. It accepts fifth argument (pointer to opaque data), that
is passed to comparator function, which then accepts three
arguments.

We have to keep one occurance of qsort() though - in NSS module
which deliberately does not link with glib.

1: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=03bf8357e8291857a435afcc3048e0b697b6cc04
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-11-24 09:53:14 +01:00
..
apparmor apparmor: Make all profiles extensible 2023-07-03 14:55:43 +02:00
meson.build meson: Always use the / operator to join paths 2021-08-11 09:16:36 +02:00
security_apparmor.c security: apparmor: Use translated disk definitions for disk type=volume 2023-10-17 14:16:15 +02:00
security_apparmor.h
security_dac.c virDomainHostdevSubsys: Convert 'type' field to proper enum type 2023-09-15 10:35:04 +02:00
security_dac.h
security_driver.c security: Update format strings in translated messages 2023-04-01 11:40:34 +02:00
security_driver.h security: make it possible to set SELinux label of child process from its binary 2023-03-10 14:09:29 -05:00
security_manager.c lib: Replace qsort() with g_qsort_with_data() 2023-11-24 09:53:14 +01:00
security_manager.h security: make it possible to set SELinux label of child process from its binary 2023-03-10 14:09:29 -05:00
security_nop.c security: make it possible to set SELinux label of child process from its binary 2023-03-10 14:09:29 -05:00
security_nop.h
security_selinux.c selinux: Drop dead code in virSecuritySELinuxSetImageLabelInternal() 2023-10-20 10:44:38 +02:00
security_selinux.h
security_stack.c security: make it possible to set SELinux label of child process from its binary 2023-03-10 14:09:29 -05:00
security_stack.h
security_util.c security: Update format strings in translated messages 2023-04-01 11:40:34 +02:00
security_util.h
virt-aa-helper.c security: apparmor: Use translated disk definitions for disk type=volume 2023-10-17 14:16:15 +02:00