boot: Deduplicate old-style loader entries.

In cases where systemd (and thus bootctl) is updated to a version
including the earlier unique-ID fix, but the corresponding new version
of systemd-boot is not installed to the ESP and run at least once,
the bootloader will report old-style entry IDs cached in the
LoaderEntries EFI variable, while bootctl will report new-style IDs for
the same entries, producing duplicate entries. This commit makes bootctl
compute and retain old-style IDs for non-auto entries so that it can
properly deduplicate entries even if the cache contains old-style IDs.
This commit is contained in:
Spencer Michaels
2019-11-21 15:50:03 -08:00
parent ae474efc3f
commit 15b82eecb6
2 changed files with 18 additions and 7 deletions
+6 -2
View File
@@ -21,6 +21,7 @@ typedef enum BootEntryType {
typedef struct BootEntry {
BootEntryType type;
char *id; /* This is the file basename without extension */
char *id_old; /* Old-style ID, for deduplication purposes. */
char *path; /* This is the full path to the drop-in file */
char *root; /* The root path in which the drop-in was found, i.e. to which 'kernel', 'efi' and 'initrd' are relative */
char *title;
@@ -54,9 +55,12 @@ typedef struct BootConfig {
static inline bool boot_config_has_entry(BootConfig *config, const char *id) {
size_t j;
for (j = 0; j < config->n_entries; j++)
if (streq(config->entries[j].id, id))
for (j = 0; j < config->n_entries; j++) {
const char* entry_id_old = config->entries[j].id_old;
if (streq(config->entries[j].id, id) ||
(entry_id_old && streq(entry_id_old, id)))
return true;
}
return false;
}