summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-03-23 17:28:44 +0100
committerLennart Poettering <lennart@poettering.net>2022-03-28 16:01:36 +0200
commitf7a7a5e2675fbcf227700e952c053411200d5d15 (patch)
tree73e77f4b9df3a857d7d604e17732a66d13f425f3 /src
parentbootspec: normalize oom handling in boot_load_efi_entry_pointers() (diff)
downloadsystemd-f7a7a5e2675fbcf227700e952c053411200d5d15.tar.xz
systemd-f7a7a5e2675fbcf227700e952c053411200d5d15.zip
bootspec: assess default/selected entries *after* we augmented entry list with entries from loader
Fixes: #22580
Diffstat (limited to 'src')
-rw-r--r--src/boot/bootctl.c12
-rw-r--r--src/login/logind-dbus.c4
-rw-r--r--src/shared/bootspec.c22
-rw-r--r--src/shared/bootspec.h8
-rw-r--r--src/systemctl/systemctl-start-special.c6
-rw-r--r--src/test/test-bootspec.c2
6 files changed, 41 insertions, 13 deletions
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index 8596939ff3..5c1d2533d7 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -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);
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 7767096619..04a72bd9b3 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -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;
diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c
index 52a1612f3d..188ab1d663 100644
--- a/src/shared/bootspec.c
+++ b/src/shared/bootspec.c
@@ -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;
}
diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h
index 720aa0484f..5c4b211ee4 100644
--- a/src/shared/bootspec.h
+++ b/src/shared/bootspec.h
@@ -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);
diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c
index da2336d3a2..6b41f4f298 100644
--- a/src/systemctl/systemctl-start-special.c
+++ b/src/systemctl/systemctl-start-special.c
@@ -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),
diff --git a/src/test/test-bootspec.c b/src/test/test-bootspec.c
index 7ba44744ba..f52b53c5f8 100644
--- a/src/test/test-bootspec.c
+++ b/src/test/test-bootspec.c
@@ -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);