]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootspec: assess default/selected entries *after* we augmented entry list with entrie...
authorLennart Poettering <lennart@poettering.net>
Wed, 23 Mar 2022 16:28:44 +0000 (17:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 28 Mar 2022 14:01:36 +0000 (16:01 +0200)
Fixes: #22580
src/boot/bootctl.c
src/login/logind-dbus.c
src/shared/bootspec.c
src/shared/bootspec.h
src/systemctl/systemctl-start-special.c
src/test/test-bootspec.c

index 8596939ff35dec3345a4289d6639ba68c1ccb9e5..5c1d2533d77d415ffba90622a0a6a8fa951b842e 100644 (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);
index 7767096619929026fc1d1bac2edfd6bc308beb62..04a72bd9b31744f07fc4c29948b22969fe4be2fd 100644 (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;
index 52a1612f3d7f300e29f1f525e750de9bac790b15..188ab1d66351b5c3e203ddfb8d1ca9c889a2dbe6 100644 (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;
 }
 
index 720aa0484f837afad012b8598462c59f3e68b709..5c4b211ee4c55e32e81201b49e290f7bbedcf6a2 100644 (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);
 
index da2336d3a2026cc2cde82a7bf8854e74e958050a..6b41f4f298fc37be19956af59cc6349b30ff34eb 100644 (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),
index 7ba44744ba67d46c3a6419b7b4dd0bce4fe88f36..f52b53c5f8ad6320f755daf5742fde6cda58c852 100644 (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);