mirror of
https://github.com/systemd/systemd.git
synced 2026-08-13 17:08:14 +00:00
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: 5fb90fa319
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user