]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: add description and ret_slot parameters to install_boot_option()
authorClayton Craft <clayton@craftyguy.net>
Thu, 30 Apr 2026 00:10:05 +0000 (17:10 -0700)
committerClayton Craft <clayton@craftyguy.net>
Thu, 21 May 2026 18:26:59 +0000 (11:26 -0700)
This moves creation of the EFI boot option description out of
install_boot_option and into the caller, and adds a ret_slot output
parameter for capturing the assigned BootOrder slot. This allows reusing
the function for installing variables with different descriptions.

src/bootctl/bootctl-install.c

index 4478f78eb354c182eacc97548bad3b70a67c3f7c..db5d982a583827dcb7b46fba1d53336986d8cd2c 100644 (file)
@@ -1354,12 +1354,16 @@ fallback:
 
 static int install_boot_option(
                 InstallContext *c,
-                const char *path) {
+                const char *path,
+                const char *description,
+                uint16_t *ret_slot) {
 
         uint16_t slot;
         int r;
 
         assert(c);
+        assert(path);
+        assert(description);
 
         if (c->esp_fd < 0)
                 return c->esp_fd;
@@ -1396,12 +1400,6 @@ static int install_boot_option(
         bool existing = r > 0;
 
         if (c->operation == INSTALL_NEW || !existing) {
-                _cleanup_free_ char *description = NULL;
-
-                r = pick_efi_boot_option_description(c->esp_fd, &description);
-                if (r < 0)
-                        return r;
-
                 r = efi_add_boot_option(
                                 slot,
                                 description,
@@ -1424,7 +1422,14 @@ static int install_boot_option(
                          description);
         }
 
-        return insert_into_order(c, slot);
+        r = insert_into_order(c, slot);
+        if (r < 0)
+                return r;
+
+        if (ret_slot)
+                *ret_slot = slot;
+
+        return 0;
 }
 
 static int are_we_installed(InstallContext *c) {
@@ -1632,7 +1637,13 @@ static int run_install(InstallContext *c) {
         }
 
         char *path = strjoina("/EFI/systemd/systemd-boot", arch, ".efi");
-        return install_boot_option(c, path);
+
+        _cleanup_free_ char *description = NULL;
+        r = pick_efi_boot_option_description(c->esp_fd, &description);
+        if (r < 0)
+                return r;
+
+        return install_boot_option(c, path, description, /* ret_slot= */ NULL);
 }
 
 int verb_install(int argc, char *argv[], uintptr_t _data, void *userdata) {