1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 23:21:22 +03:00

bootspec: assess default/selected entries *after* we augmented entry list with entries from loader

Fixes: #22580
This commit is contained in:
Lennart Poettering 2022-03-23 17:28:44 +01:00
parent 92067ab672
commit f7a7a5e267
6 changed files with 41 additions and 13 deletions

View File

@ -687,7 +687,7 @@ static int status_entries(
const char *xbootldr_path,
sd_id128_t xbootldr_partition_uuid) {
_cleanup_(boot_config_free) BootConfig config = {};
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
sd_id128_t dollar_boot_partition_uuid;
const char *dollar_boot_path;
int r;
@ -713,6 +713,10 @@ static int status_entries(
if (r < 0)
return r;
r = boot_config_select_special_entries(&config);
if (r < 0)
return r;
if (config.default_entry < 0)
printf("%zu entries, no entry could be determined as default.\n", config.n_entries);
else {
@ -1788,7 +1792,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
}
static int verb_list(int argc, char *argv[], void *userdata) {
_cleanup_(boot_config_free) BootConfig config = {};
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
_cleanup_strv_free_ char **efi_entries = NULL;
dev_t esp_devid = 0, xbootldr_devid = 0;
int r;
@ -1824,6 +1828,10 @@ static int verb_list(int argc, char *argv[], void *userdata) {
else
(void) boot_entries_augment_from_loader(&config, efi_entries, /* only_auto= */ false);
r = boot_config_select_special_entries(&config);
if (r < 0)
return r;
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
pager_open(arg_pager_flags);

View File

@ -3002,7 +3002,7 @@ static int property_get_reboot_to_boot_loader_entry(
}
static int boot_loader_entry_exists(Manager *m, const char *id) {
_cleanup_(boot_config_free) BootConfig config = {};
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
int r;
assert(m);
@ -3157,7 +3157,7 @@ static int property_get_boot_loader_entries(
void *userdata,
sd_bus_error *error) {
_cleanup_(boot_config_free) BootConfig config = {};
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
Manager *m = userdata;
size_t i;
int r;

View File

@ -819,6 +819,21 @@ static int boot_load_efi_entry_pointers(BootConfig *config) {
return 1;
}
int boot_config_select_special_entries(BootConfig *config) {
int r;
assert(config);
r = boot_load_efi_entry_pointers(config);
if (r < 0)
return r;
config->default_entry = boot_entries_select_default(config);
config->selected_entry = boot_entries_select_selected(config);
return 0;
}
int boot_entries_load_config(
const char *esp_path,
const char *xbootldr_path,
@ -864,13 +879,6 @@ int boot_entries_load_config(
if (r < 0)
return log_error_errno(r, "Failed to uniquify boot entries: %m");
r = boot_load_efi_entry_pointers(config);
if (r < 0)
return r;
config->default_entry = boot_entries_select_default(config);
config->selected_entry = boot_entries_select_selected(config);
return 0;
}

View File

@ -62,6 +62,12 @@ typedef struct BootConfig {
Set *inodes_seen;
} BootConfig;
#define BOOT_CONFIG_NULL \
{ \
.default_entry = -1, \
.selected_entry = -1, \
}
static inline BootEntry* boot_config_find_entry(BootConfig *config, const char *id) {
assert(config);
assert(id);
@ -88,6 +94,8 @@ int boot_entries_load_config(const char *esp_path, const char *xbootldr_path, Bo
int boot_entries_load_config_auto(const char *override_esp_path, const char *override_xbootldr_path, BootConfig *config);
int boot_entries_augment_from_loader(BootConfig *config, char **list, bool only_auto);
int boot_config_select_special_entries(BootConfig *config);
static inline const char* boot_entry_title(const BootEntry *entry) {
assert(entry);

View File

@ -18,7 +18,7 @@
#include "systemctl.h"
static int load_kexec_kernel(void) {
_cleanup_(boot_config_free) BootConfig config = {};
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
_cleanup_free_ char *kernel = NULL, *initrd = NULL, *options = NULL;
const BootEntry *e;
pid_t pid;
@ -43,6 +43,10 @@ static int load_kexec_kernel(void) {
if (r < 0)
return r;
r = boot_config_select_special_entries(&config);
if (r < 0)
return r;
e = boot_config_default_entry(&config);
if (!e)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT),

View File

@ -61,7 +61,7 @@ TEST_RET(bootspec_sort) {
};
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
_cleanup_(boot_config_free) BootConfig config = {};
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
assert_se(mkdtemp_malloc("/tmp/bootspec-testXXXXXX", &d) >= 0);