From: David Tardon Date: Wed, 7 May 2025 14:11:38 +0000 (+0200) Subject: udevadm-trigger: use string table to parse scan type X-Git-Tag: v258-rc1~661^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F37293%2Fhead;p=thirdparty%2Fsystemd.git udevadm-trigger: use string table to parse scan type --- diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 9163824befd..94a3a4037a9 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -17,6 +17,7 @@ #include "process-util.h" #include "set.h" #include "static-destruct.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "udevadm.h" @@ -27,6 +28,8 @@ typedef enum { SCAN_TYPE_DEVICES, SCAN_TYPE_SUBSYSTEMS, SCAN_TYPE_ALL, + _SCAN_TYPE_MAX, + _SCAN_TYPE_INVALID = -EINVAL, } ScanType; static bool arg_verbose = false; @@ -64,6 +67,14 @@ STATIC_DESTRUCTOR_REGISTER(arg_sysname_match, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_tag_match, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_prioritized_subsystems, strv_freep); +static const char *scan_type_table[_SCAN_TYPE_MAX] = { + [SCAN_TYPE_DEVICES] = "devices", + [SCAN_TYPE_SUBSYSTEMS] = "subsystems", + [SCAN_TYPE_ALL] = "all", +}; + +DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(scan_type, ScanType); + static int exec_list( sd_device_enumerator *e, sd_device_action_t action, @@ -406,13 +417,8 @@ static int parse_argv(int argc, char *argv[]) { break; case 't': - if (streq(optarg, "devices")) - arg_scan_type = SCAN_TYPE_DEVICES; - else if (streq(optarg, "subsystems")) - arg_scan_type = SCAN_TYPE_SUBSYSTEMS; - else if (streq(optarg, "all")) - arg_scan_type = SCAN_TYPE_ALL; - else + arg_scan_type = scan_type_from_string(optarg); + if (arg_scan_type < 0) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown type --type=%s", optarg); break;