]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: return recognizable Varlink error when we cannot determine the boot entry...
authorLennart Poettering <lennart@amutable.com>
Fri, 23 Jan 2026 20:04:55 +0000 (21:04 +0100)
committerLennart Poettering <lennart@amutable.com>
Fri, 6 Feb 2026 22:16:50 +0000 (23:16 +0100)
When running "bootctl install" on an empty --root= dir, we don't know
which token to use, and the operation will fail. Make sure to return an
explicit error about this.

This introduces a recognizable low-level error for this (EUNATCH), and
then turns this into a recognizable Varlink error.

(I made sure that the old low-level error EINVAL wasn't load-bearing,
and it is safe to change this.)

src/bootctl/bootctl-install.c
src/shared/boot-entry.c
src/shared/varlink-io.systemd.BootControl.c

index 976c5380e1f167cbfd07f39a7e02ce0dbefdae1c..2d9a151212dddf71a8c4944824eed05f25484ab4 100644 (file)
@@ -2087,6 +2087,8 @@ int vl_method_install(
                 return r;
 
         r = run_install(&p.context);
+        if (r == -EUNATCH) /* no boot entry token is set */
+                return sd_varlink_error(link, "io.systemd.BootControl.BootEntryTokenUnavailable", NULL);
         if (r < 0)
                 return r;
 
index 042522951cc911f01852250ff5b2362a270e6509..0f1d8090247a6eec8876c78e7b46dd02fa2be378 100644 (file)
@@ -155,6 +155,8 @@ int boot_entry_token_ensure_at(
         assert(type);
         assert(token);
 
+        /* Returns -EUNATCH if the selected token is not set */
+
         if (*token)
                 return 0; /* Already set. */
 
@@ -181,7 +183,7 @@ int boot_entry_token_ensure_at(
                                 return r;
                 }
 
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                return log_error_errno(SYNTHETIC_ERRNO(EUNATCH),
                                        "No machine ID set, and /etc/os-release carries no ID=/IMAGE_ID= fields.");
 
         case BOOT_ENTRY_TOKEN_MACHINE_ID:
@@ -189,14 +191,14 @@ int boot_entry_token_ensure_at(
                 if (r != 0)
                         return r;
 
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No machine ID set.");
+                return log_error_errno(SYNTHETIC_ERRNO(EUNATCH), "No machine ID set.");
 
         case BOOT_ENTRY_TOKEN_OS_IMAGE_ID:
                 r = entry_token_from_os_release(rfd, type, token);
                 if (r != 0)
                         return r;
 
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                return log_error_errno(SYNTHETIC_ERRNO(EUNATCH),
                                        "IMAGE_ID= field not set in /etc/os-release.");
 
         case BOOT_ENTRY_TOKEN_OS_ID:
@@ -204,12 +206,12 @@ int boot_entry_token_ensure_at(
                 if (r != 0)
                         return r;
 
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                return log_error_errno(SYNTHETIC_ERRNO(EUNATCH),
                                        "ID= field not set in /etc/os-release.");
 
         case BOOT_ENTRY_TOKEN_LITERAL:
                 /* In this case, the token should be already set by the user input. */
-                return -EINVAL;
+                return log_error_errno(SYNTHETIC_ERRNO(EUNATCH), "Literal token indicated but not specified.");
 
         default:
                 assert_not_reached();
index 453002aaa9f8c466555c19fae5c434bc4a6da7df..a24b4b076e0175a2f44026bc2bf4672e5a20d51c 100644 (file)
@@ -143,6 +143,9 @@ static SD_VARLINK_DEFINE_ERROR(
 static SD_VARLINK_DEFINE_ERROR(
                 NoESPFound);
 
+static SD_VARLINK_DEFINE_ERROR(
+                BootEntryTokenUnavailable);
+
 SD_VARLINK_DEFINE_INTERFACE(
                 io_systemd_BootControl,
                 "io.systemd.BootControl",
@@ -172,4 +175,6 @@ SD_VARLINK_DEFINE_INTERFACE(
                 SD_VARLINK_SYMBOL_COMMENT("No boot entry defined."),
                 &vl_error_NoSuchBootEntry,
                 SD_VARLINK_SYMBOL_COMMENT("No EFI System Partition (ESP) found."),
-                &vl_error_NoESPFound);
+                &vl_error_NoESPFound,
+                SD_VARLINK_SYMBOL_COMMENT("The select boot entry token could not be determined."),
+                &vl_error_BootEntryTokenUnavailable);