From: Lennart Poettering Date: Fri, 5 Jul 2024 07:52:58 +0000 (+0200) Subject: bootspec: implement sorting by tries left/done, to match what sd-boot does X-Git-Tag: v257-rc1~917^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=35451a32043504013eed5725c8be46b36ccdf71a;p=thirdparty%2Fsystemd.git bootspec: implement sorting by tries left/done, to match what sd-boot does --- diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 05b1d045060..e7aace151b4 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -505,6 +505,12 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { assert(a); assert(b); + /* This mimics a function of the same name in src/boot/efi/sd-boot.c */ + + r = CMP(a->tries_left == 0, b->tries_left == 0); + if (r != 0) + return r; + r = CMP(!a->sort_key, !b->sort_key); if (r != 0) return r; @@ -523,7 +529,18 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { return r; } - return -strverscmp_improved(a->id, b->id); + r = -strverscmp_improved(a->id, b->id); + if (r != 0) + return r; + + if (a->tries_left != UINT_MAX || b->tries_left != UINT_MAX) + return 0; + + r = -CMP(a->tries_left, b->tries_left); + if (r != 0) + return r; + + return CMP(a->tries_done, b->tries_done); } static int config_check_inode_relevant_and_unseen(BootConfig *config, int fd, const char *fname) {