From: Lennart Poettering Date: Wed, 19 Jun 2024 11:54:35 +0000 (+0200) Subject: bootctl: normalize how we report no boot entries found X-Git-Tag: v257-rc1~1089^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e10f3a7e800ad67be8d8b14ae158a27438814f0;p=thirdparty%2Fsystemd.git bootctl: normalize how we report no boot entries found 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. --- diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c index 0b222073b4d..d2c7d50d12b 100644 --- a/src/boot/bootctl-status.c +++ b/src/boot/bootctl-status.c @@ -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)); } diff --git a/src/shared/varlink-io.systemd.BootControl.c b/src/shared/varlink-io.systemd.BootControl.c index 500e07243c7..2557384c6ad 100644 --- a/src/shared/varlink-io.systemd.BootControl.c +++ b/src/shared/varlink-io.systemd.BootControl.c @@ -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); diff --git a/test/units/TEST-74-AUX-UTILS.bootctl.sh b/test/units/TEST-74-AUX-UTILS.bootctl.sh index 78c0e6e5d9d..5331f5f8b40 100755 --- a/test/units/TEST-74-AUX-UTILS.bootctl.sh +++ b/test/units/TEST-74-AUX-UTILS.bootctl.sh @@ -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.