From: Lennart Poettering Date: Thu, 26 Mar 2026 22:44:59 +0000 (+0100) Subject: bootspec: honour profile number when sorting properly X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6a4a4f0302e78fda9ff2cfb7ac6a5644aabc4fc2;p=thirdparty%2Fsystemd.git bootspec: honour profile number when sorting properly This corrects sorting of menu entries regarding profile numbers: 1. If the profile number is unset, let's treat this identical to profile 0, when ordering stuff, because an item with no profile is conceptually the same as an item with only a profile 0. 2. Let's take the profile number into account also if sort keys are used. This was makes profiles work sensibly in type 1 entries, via the recently added "profile" stanza. Follow-up for: 5fb90fa3194d998a971b21e4a643670ae5903f85 --- diff --git a/src/boot/boot.c b/src/boot/boot.c index 4a5102f45c7..904f9bf5894 100644 --- a/src/boot/boot.c +++ b/src/boot/boot.c @@ -1745,6 +1745,12 @@ static void config_load_smbios_entries( } } +static unsigned boot_entry_profile(const BootEntry *a) { + assert(a); + + return a->profile == UINT_MAX ? 0 : a->profile; +} + static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { int r; @@ -1778,6 +1784,10 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { r = -strverscmp_improved(a->version, b->version); if (r != 0) return r; + + r = CMP(boot_entry_profile(a), boot_entry_profile(b)); + if (r != 0) + return r; } /* Now order by ID. The version is likely part of the ID, thus note that this will generatelly put @@ -1792,7 +1802,7 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { /* Note: the strverscmp_improved() call above checked for us that we are looking at the very * same id, hence at this point we only need to compare profile numbers, since we know they * belong to the same UKI. */ - r = CMP(a->profile, b->profile); + r = CMP(boot_entry_profile(a), boot_entry_profile(b)); if (r != 0) return r; } diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 2a898067f81..36eb2e7086e 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -555,6 +555,12 @@ static int boot_loader_read_conf_path(BootConfig *config, const char *root, cons return boot_loader_read_conf(config, f, full); } +static unsigned boot_entry_profile(const BootEntry *a) { + assert(a); + + return a->profile == UINT_MAX ? 0 : a->profile; +} + static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { int r; @@ -583,6 +589,10 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { r = -strverscmp_improved(a->version, b->version); if (r != 0) return r; + + r = CMP(boot_entry_profile(a), boot_entry_profile(b)); + if (r != 0) + return r; } r = -strverscmp_improved(a->id_without_profile ?: a->id, b->id_without_profile ?: b->id); @@ -592,7 +602,7 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) { if (a->id_without_profile && b->id_without_profile) { /* The strverscmp_improved() call above already established that we are talking about the * same image here, hence order by profile, if there is one */ - r = CMP(a->profile, b->profile); + r = CMP(boot_entry_profile(a), boot_entry_profile(b)); if (r != 0) return r; }