Skip to content

Commit e2cda71

Browse files
committed
bootctl: accept makeEntryDirectory in Install Varlink method
The CLI defaults --make-entry-directory to off and lets callers opt in or request auto mode. The Varlink Install method always ran in auto mode with no way to override it. Expose the tri-state so IPC callers can match the CLI behaviour.
1 parent ca7fd21 commit e2cda71

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/bootctl/bootctl-install.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,14 +2113,15 @@ int vl_method_install(
21132113
};
21142114

21152115
static const sd_json_dispatch_field dispatch_table[] = {
2116-
{ "operation", SD_JSON_VARIANT_STRING, json_dispatch_install_operation, voffsetof(p, context.operation), SD_JSON_MANDATORY },
2117-
{ "graceful", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, voffsetof(p, context.graceful), 0 },
2118-
{ "rootFileDescriptor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, voffsetof(p, root_fd_index), 0 },
2119-
{ "rootDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, voffsetof(p, context.root), 0 },
2120-
{ "espPath", SD_JSON_VARIANT_STRING, json_dispatch_path, voffsetof(p, esp_path), 0 },
2121-
{ "xbootldrPath", SD_JSON_VARIANT_STRING, json_dispatch_path, voffsetof(p, xbootldr_path), 0 },
2122-
{ "bootEntryTokenType", SD_JSON_VARIANT_STRING, json_dispatch_boot_entry_token_type, voffsetof(p, context.entry_token_type), 0 },
2123-
{ "touchVariables", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, voffsetof(p, context.touch_variables), 0 },
2116+
{ "operation", SD_JSON_VARIANT_STRING, json_dispatch_install_operation, voffsetof(p, context.operation), SD_JSON_MANDATORY },
2117+
{ "graceful", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, voffsetof(p, context.graceful), 0 },
2118+
{ "rootFileDescriptor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, voffsetof(p, root_fd_index), 0 },
2119+
{ "rootDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, voffsetof(p, context.root), 0 },
2120+
{ "espPath", SD_JSON_VARIANT_STRING, json_dispatch_path, voffsetof(p, esp_path), 0 },
2121+
{ "xbootldrPath", SD_JSON_VARIANT_STRING, json_dispatch_path, voffsetof(p, xbootldr_path), 0 },
2122+
{ "bootEntryTokenType", SD_JSON_VARIANT_STRING, json_dispatch_boot_entry_token_type, voffsetof(p, context.entry_token_type), 0 },
2123+
{ "makeEntryDirectory", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, voffsetof(p, context.make_entry_directory), 0 },
2124+
{ "touchVariables", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, voffsetof(p, context.touch_variables), 0 },
21242125
{},
21252126
};
21262127

src/shared/varlink-io.systemd.BootControl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ static SD_VARLINK_DEFINE_METHOD(
137137
SD_VARLINK_DEFINE_INPUT(xbootldrPath, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
138138
SD_VARLINK_FIELD_COMMENT("Selects how to identify boot entries"),
139139
SD_VARLINK_DEFINE_INPUT_BY_TYPE(bootEntryTokenType, BootEntryTokenType, SD_VARLINK_NULLABLE),
140+
SD_VARLINK_FIELD_COMMENT("Whether to create the '$BOOT/ENTRY-TOKEN/' directory for Boot Loader Specification Type #1 snippets. If not specified this is decided automatically."),
141+
SD_VARLINK_DEFINE_INPUT(makeEntryDirectory, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
140142
SD_VARLINK_FIELD_COMMENT("If true the boot loader will be registered in an EFI boot entry via EFI variables, otherwise this is omitted"),
141143
SD_VARLINK_DEFINE_INPUT(touchVariables, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE));
142144

test/units/TEST-87-AUX-UTILS-VM.bootctl.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,25 @@ testcase_install_varlink() {
459459
FAKE_BOOT="$(mktemp --directory /tmp/test-bootctl-boot.XXXXXXXXXX)"
460460
SYSTEMD_RELAX_ESP_CHECKS=yes SYSTEMD_RELAX_XBOOTLDR_CHECKS=yes SYSTEMD_LOG_TARGET=console \
461461
varlinkctl call --quiet "$(type -p bootctl)" io.systemd.BootControl.Install \
462-
"{\"operation\":\"new\",\"touchVariables\":false,\"espPath\":\"$FAKE_ESP\",\"xbootldrPath\":\"$FAKE_BOOT\"}"
462+
"{\"operation\":\"new\",\"touchVariables\":false,\"espPath\":\"$FAKE_ESP\",\"xbootldrPath\":\"$FAKE_BOOT\",\"makeEntryDirectory\":false}"
463463
test -f "$FAKE_ESP/EFI/systemd/systemd-boot$(bootctl --print-efi-architecture).efi"
464464
test -f "$FAKE_BOOT/loader/entries.srel"
465+
# makeEntryDirectory:false means loader.conf must not gain a "default" line and no entry
466+
# token directory is created under $BOOT.
467+
(! grep '^default ' "$FAKE_ESP/loader/loader.conf" >/dev/null)
468+
469+
# Same again into fresh directories with makeEntryDirectory:true, and check loader.conf now
470+
# gets a "default <entry-token>-*" line and the entry token directory shows up under $BOOT.
471+
rm -rf "$FAKE_ESP" "$FAKE_BOOT"
472+
FAKE_ESP="$(mktemp --directory /tmp/test-bootctl-esp.XXXXXXXXXX)"
473+
FAKE_BOOT="$(mktemp --directory /tmp/test-bootctl-boot.XXXXXXXXXX)"
474+
SYSTEMD_RELAX_ESP_CHECKS=yes SYSTEMD_RELAX_XBOOTLDR_CHECKS=yes SYSTEMD_LOG_TARGET=console \
475+
varlinkctl call --quiet "$(type -p bootctl)" io.systemd.BootControl.Install \
476+
"{\"operation\":\"new\",\"touchVariables\":false,\"espPath\":\"$FAKE_ESP\",\"xbootldrPath\":\"$FAKE_BOOT\",\"makeEntryDirectory\":true}"
477+
local TOKEN
478+
TOKEN="$(sed -n 's/^default \(.*\)-\*$/\1/p' "$FAKE_ESP/loader/loader.conf")"
479+
test -n "$TOKEN"
480+
test -d "$FAKE_BOOT/$TOKEN"
465481
}
466482

467483
cleanup_link() {

0 commit comments

Comments
 (0)