From: Yu Watanabe Date: Sun, 2 Feb 2025 04:30:26 +0000 (+0900) Subject: udevadm: several cleanups around parse_device_action() X-Git-Tag: v258-rc1~1413^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be73f6e35b81d6e534440c14b2cb40718a86c988;p=thirdparty%2Fsystemd.git udevadm: several cleanups around parse_device_action() - drop unnecessary one line function dump_device_action_table(), - make parse_device_action() log about invalid action string, - rename output argument of parse_device_action(). --- diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 463eb7ea9ef..00279ae01f0 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -961,7 +961,3 @@ static const char* const device_action_table[_SD_DEVICE_ACTION_MAX] = { }; DEFINE_STRING_TABLE_LOOKUP(device_action, sd_device_action_t); - -void dump_device_action_table(void) { - DUMP_STRING_TABLE(device_action, sd_device_action_t, _SD_DEVICE_ACTION_MAX); -} diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h index 4165c85023b..aa42cbb2a19 100644 --- a/src/libsystemd/sd-device/device-private.h +++ b/src/libsystemd/sd-device/device-private.h @@ -77,4 +77,3 @@ int device_read_uevent_file(sd_device *device); int device_set_action(sd_device *device, sd_device_action_t a); sd_device_action_t device_action_from_string(const char *s) _pure_; const char* device_action_to_string(sd_device_action_t a) _const_; -void dump_device_action_table(void); diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 382897efd46..13ecbe97738 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -45,10 +45,8 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'a': r = parse_device_action(optarg, &arg_action); - if (r < 0) - return log_error_errno(r, "Invalid action '%s'", optarg); - if (r == 0) - return 0; + if (r <= 0) + return r; break; case 'V': return print_version(); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index c3f56d2d81b..a6da337d7cb 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -60,10 +60,8 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'a': r = parse_device_action(optarg, &arg_action); - if (r < 0) - return log_error_errno(r, "Invalid action '%s'", optarg); - if (r == 0) - return 0; + if (r <= 0) + return r; break; case 'N': arg_resolve_name_timing = resolve_name_timing_from_string(optarg); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 808c383e21d..8ab4b497894 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -369,10 +369,8 @@ int trigger_main(int argc, char *argv[], void *userdata) { break; case 'c': r = parse_device_action(optarg, &action); - if (r < 0) - return log_error_errno(r, "Unknown action '%s'", optarg); - if (r == 0) - return 0; + if (r <= 0) + return r; break; case 's': r = sd_device_enumerator_add_match_subsystem(e, optarg, true); diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c index 641adb4f974..858c23f586d 100644 --- a/src/udev/udevadm-util.c +++ b/src/udev/udevadm-util.c @@ -10,6 +10,7 @@ #include "constants.h" #include "device-private.h" #include "path-util.h" +#include "string-table.h" #include "udev-ctrl.h" #include "udev-varlink.h" #include "udevadm-util.h" @@ -110,22 +111,19 @@ int find_device_with_action(const char *id, sd_device_action_t action, sd_device return 0; } -int parse_device_action(const char *str, sd_device_action_t *action) { - sd_device_action_t a; +int parse_device_action(const char *str, sd_device_action_t *ret) { assert(str); - assert(action); - if (streq(str, "help")) { - dump_device_action_table(); - return 0; - } + if (streq(str, "help")) + return DUMP_STRING_TABLE(device_action, sd_device_action_t, _SD_DEVICE_ACTION_MAX); - a = device_action_from_string(str); + sd_device_action_t a = device_action_from_string(str); if (a < 0) - return a; + return log_error_errno(a, "Invalid action '%s'.", str); - *action = a; + if (ret) + *ret = a; return 1; } diff --git a/src/udev/udevadm-util.h b/src/udev/udevadm-util.h index 0a8b31ada7f..08462985022 100644 --- a/src/udev/udevadm-util.h +++ b/src/udev/udevadm-util.h @@ -5,6 +5,6 @@ int find_device(const char *id, const char *prefix, sd_device **ret); int find_device_with_action(const char *id, sd_device_action_t action, sd_device **ret); -int parse_device_action(const char *str, sd_device_action_t *action); +int parse_device_action(const char *str, sd_device_action_t *ret); int udev_ping(usec_t timeout, bool ignore_connection_failure); int search_rules_files(char * const *a, const char *root, char ***ret);