From 9e10f3a7e800ad67be8d8b14ae158a27438814f0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Jun 2024 13:54:35 +0200 Subject: [PATCH] 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. --- src/boot/bootctl-status.c | 8 +++++++- src/shared/varlink-io.systemd.BootControl.c | 6 +++++- test/units/TEST-74-AUX-UTILS.bootctl.sh | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c index 0b222073b4..d2c7d50d12 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 500e07243c..2557384c6a 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 78c0e6e5d9..5331f5f8b4 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.