From: Lennart Poettering Date: Mon, 8 Sep 2025 08:16:22 +0000 (+0200) Subject: bootctl: parse install source via our usual string table helpers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ee2f6657f8ef5154784d3977b290a38fb25fe26;p=thirdparty%2Fsystemd.git bootctl: parse install source via our usual string table helpers --- diff --git a/src/bootctl/bootctl.c b/src/bootctl/bootctl.c index 889c5f91b67..dee65d51d7f 100644 --- a/src/bootctl/bootctl.c +++ b/src/bootctl/bootctl.c @@ -31,6 +31,7 @@ #include "parse-argument.h" #include "path-util.h" #include "pretty-print.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "utf8.h" @@ -93,6 +94,14 @@ STATIC_DESTRUCTOR_REGISTER(arg_certificate_source, freep); STATIC_DESTRUCTOR_REGISTER(arg_private_key, freep); STATIC_DESTRUCTOR_REGISTER(arg_private_key_source, freep); +static const char* const install_source_table[_INSTALL_SOURCE_MAX] = { + [INSTALL_SOURCE_IMAGE] = "image", + [INSTALL_SOURCE_HOST] = "host", + [INSTALL_SOURCE_AUTO] = "auto", +}; + +DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(install_source, InstallSource); + int acquire_esp( int unprivileged_mode, bool graceful, @@ -481,18 +490,14 @@ static int parse_argv(int argc, char *argv[]) { return r; break; - case ARG_INSTALL_SOURCE: - if (streq(optarg, "auto")) - arg_install_source = INSTALL_SOURCE_AUTO; - else if (streq(optarg, "image")) - arg_install_source = INSTALL_SOURCE_IMAGE; - else if (streq(optarg, "host")) - arg_install_source = INSTALL_SOURCE_HOST; - else - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Unexpected parameter for --install-source=: %s", optarg); + case ARG_INSTALL_SOURCE: { + InstallSource is = install_source_from_string(optarg); + if (is < 0) + return log_error_errno(is, "Unexpected parameter for --install-source=: %s", optarg); + arg_install_source = is; break; + } case 'p': arg_print_esp_path = true;