1
0
mirror of https://github.com/systemd/systemd synced 2024-07-01 07:34:28 +00:00

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.
This commit is contained in:
Lennart Poettering 2024-06-19 13:54:35 +02:00
parent 5e542f8706
commit 9e10f3a7e8
3 changed files with 13 additions and 3 deletions

View 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));
}

View 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);

View File

@ -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.