Merge pull request #13953 from SpencerMichaels/systemd-boot-efistub-id-fix

boot: Fix default/oneshot selection for EFISTUB entries
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-12-04 13:30:52 +01:00
committed by GitHub
3 changed files with 48 additions and 23 deletions
+10 -5
View File
@@ -36,6 +36,7 @@ static void boot_entry_free(BootEntry *entry) {
assert(entry);
free(entry->id);
free(entry->id_old);
free(entry->path);
free(entry->root);
free(entry->title);
@@ -73,12 +74,13 @@ static int boot_entry_load(
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid loader entry file suffix: %s", path);
b = basename(path);
tmp.id = strndup(b, c - b);
if (!tmp.id)
tmp.id = strdup(b);
tmp.id_old = strndup(b, c - b);
if (!tmp.id || !tmp.id_old)
return log_oom();
if (!efi_loader_entry_name_valid(tmp.id))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid loader entry filename: %s", path);
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid loader entry: %s", tmp.id);
tmp.path = strdup(path);
if (!tmp.path)
@@ -289,6 +291,7 @@ static int boot_entry_load_unified(
};
_cleanup_fclose_ FILE *f = NULL;
const char *k;
char *b;
int r;
assert(root);
@@ -314,8 +317,10 @@ static int boot_entry_load_unified(
if (!os_pretty_name || !os_id || !(version_id || build_id))
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Missing fields in os-release data from unified kernel image %s, refusing.", path);
tmp.id = strjoin(os_id, "-", version_id ?: build_id);
if (!tmp.id)
b = basename(path);
tmp.id = strdup(b);
tmp.id_old = strjoin(os_id, "-", version_id ?: build_id);
if (!tmp.id || !tmp.id_old)
return log_oom();
if (!efi_loader_entry_name_valid(tmp.id))
+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;
}