]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: parse install source via our usual string table helpers
authorLennart Poettering <lennart@amutable.com>
Mon, 8 Sep 2025 08:16:22 +0000 (10:16 +0200)
committerLennart Poettering <lennart@amutable.com>
Fri, 6 Feb 2026 22:16:00 +0000 (23:16 +0100)
src/bootctl/bootctl.c

index 889c5f91b67ab2879b2a58f2f1abfc79e0793ef9..dee65d51d7f23bbd0b160d253df69bc2f99724a6 100644 (file)
@@ -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;