From 3b5fc5fb1bf4b1601c0e54809b0f475c43d52f68 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 29 Mar 2023 11:14:02 +0900 Subject: [PATCH] boot-entry: prioritize machine ID only when it is not randomly generated Preparation for later commits. The parameter will be used in kernel-install later. --- src/boot/bootctl-util.c | 1 + src/shared/boot-entry.c | 15 ++++++++++++--- src/shared/boot-entry.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/boot/bootctl-util.c b/src/boot/bootctl-util.c index d93cc203184..7259f177a80 100644 --- a/src/boot/bootctl-util.c +++ b/src/boot/bootctl-util.c @@ -120,6 +120,7 @@ int settle_entry_token(void) { arg_root, etc_kernel(), arg_machine_id, + /* machine_id_is_random = */ false, &arg_entry_token_type, &arg_entry_token); if (r < 0) diff --git a/src/shared/boot-entry.c b/src/shared/boot-entry.c index 90e72bd7547..23877fecba7 100644 --- a/src/shared/boot-entry.c +++ b/src/shared/boot-entry.c @@ -115,6 +115,7 @@ int boot_entry_token_ensure( const char *root, const char *etc_kernel, sd_id128_t machine_id, + bool machine_id_is_random, BootEntryTokenType *type, char **token) { @@ -133,14 +134,22 @@ int boot_entry_token_ensure( if (r != 0) return r; - r = entry_token_from_machine_id(machine_id, type, token); - if (r != 0) - return r; + if (!machine_id_is_random) { + r = entry_token_from_machine_id(machine_id, type, token); + if (r != 0) + return r; + } r = entry_token_from_os_release(root, type, token); if (r != 0) return r; + if (machine_id_is_random) { + r = entry_token_from_machine_id(machine_id, type, token); + if (r != 0) + return r; + } + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No machine ID set, and %s/etc/os-release carries no ID=/IMAGE_ID= fields.", strempty(root)); diff --git a/src/shared/boot-entry.h b/src/shared/boot-entry.h index 97b30702bce..73781a9027d 100644 --- a/src/shared/boot-entry.h +++ b/src/shared/boot-entry.h @@ -19,6 +19,7 @@ int boot_entry_token_ensure( const char *root, const char *etc_kernel, /* will be prefixed with root, typically /etc/kernel. */ sd_id128_t machine_id, + bool machine_id_is_random, BootEntryTokenType *type, /* input and output */ char **token); /* output, but do not pass uninitialized value. */