]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: normalize how we report no boot entries found
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Jun 2024 11:54:35 +0000 (13:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 20 Jun 2024 08:02:40 +0000 (10:02 +0200)
This normalizes how we report an empty list of boot entries in
ListBootEntries(). Our usual pattern is to return one item per method
call, but when there is none we usually return a NoSuchXYZ error. Do so
here too.

Before this we'd return a null item instead here, and only here.

This is a minor compat break, but given that this IPC interface is very
new and probably not used so far (we don't use it in our code at least,
and google doesn#t find any other use) I think this normalization is OK
at this point.

src/boot/bootctl-status.c
src/shared/varlink-io.systemd.BootControl.c
test/units/TEST-74-AUX-UTILS.bootctl.sh

index 0b222073b4dc554a8566a7e0c0bfcb03358fd749..d2c7d50d12bba7fd2e641fdf5f7a1ee7b8ce96ca 100644 (file)
@@ -845,6 +845,9 @@ int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, Varl
         if (sd_json_variant_elements(parameters) > 0)
                 return varlink_error_invalid_parameter(link, parameters);
 
+        if (!FLAGS_SET(flags, VARLINK_METHOD_MORE))
+                return varlink_error(link, VARLINK_ERROR_EXPECTED_MORE, NULL);
+
         r = acquire_esp(/* unprivileged_mode= */ false,
                         /* graceful= */ false,
                         /* ret_part= */ NULL,
@@ -885,5 +888,8 @@ int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, Varl
                         return r;
         }
 
-        return varlink_replybo(link, SD_JSON_BUILD_PAIR_CONDITION(!!previous, "entry", SD_JSON_BUILD_VARIANT(previous)));
+        if (!previous)
+                return varlink_error(link, "io.systemd.BootControl.NoSuchBootEntry", NULL);
+
+        return varlink_replybo(link, SD_JSON_BUILD_PAIR_VARIANT("entry", previous));
 }
index 500e07243c7085009ec1f1aec297e9a7c0ea3519..2557384c6adeca1933831fbd85c27e9ec25f9647 100644 (file)
@@ -48,6 +48,9 @@ static VARLINK_DEFINE_METHOD(
 static VARLINK_DEFINE_ERROR(
                 RebootToFirmwareNotSupported);
 
+static VARLINK_DEFINE_ERROR(
+                NoSuchBootEntry);
+
 VARLINK_DEFINE_INTERFACE(
                 io_systemd_BootControl,
                 "io.systemd.BootControl",
@@ -56,4 +59,5 @@ VARLINK_DEFINE_INTERFACE(
                 &vl_method_ListBootEntries,
                 &vl_method_SetRebootToFirmware,
                 &vl_method_GetRebootToFirmware,
-                &vl_error_RebootToFirmwareNotSupported);
+                &vl_error_RebootToFirmwareNotSupported,
+                &vl_error_NoSuchBootEntry);
index 78c0e6e5d9d93880c14cc716036774985fd4e03f..5331f5f8b4025edfbd91009eff9edba056829226 100755 (executable)
@@ -264,7 +264,7 @@ EOF
 }
 
 testcase_bootctl_varlink() {
-    varlinkctl call --collect /run/systemd/io.systemd.BootControl io.systemd.BootControl.ListBootEntries '{}'
+    (varlinkctl call --collect /run/systemd/io.systemd.BootControl io.systemd.BootControl.ListBootEntries '{}' ||:)
 
     # We may have UEFI in the test environment.
     # If we don't have UEFI then we can test whether bootctl's varlink API fails cleanly.