mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 23:20:32 +00:00
udevadm: introduce parse_device_action() helper function
This commit is contained in:
@@ -50,25 +50,17 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
{}
|
||||
};
|
||||
|
||||
int c;
|
||||
int r, c;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0)
|
||||
switch (c) {
|
||||
case 'a': {
|
||||
sd_device_action_t a;
|
||||
|
||||
if (streq(optarg, "help")) {
|
||||
dump_device_action_table();
|
||||
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;
|
||||
}
|
||||
|
||||
a = device_action_from_string(optarg);
|
||||
if (a < 0)
|
||||
return log_error_errno(a, "Invalid action '%s'", optarg);
|
||||
|
||||
arg_action = a;
|
||||
break;
|
||||
}
|
||||
case 'N':
|
||||
arg_resolve_name_timing = resolve_name_timing_from_string(optarg);
|
||||
if (arg_resolve_name_timing < 0)
|
||||
|
||||
@@ -312,17 +312,13 @@ int trigger_main(int argc, char *argv[], void *userdata) {
|
||||
else
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown type --type=%s", optarg);
|
||||
break;
|
||||
case 'c': {
|
||||
if (streq(optarg, "help")) {
|
||||
dump_device_action_table();
|
||||
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;
|
||||
}
|
||||
|
||||
action = device_action_from_string(optarg);
|
||||
if (action < 0)
|
||||
return log_error_errno(action, "Unknown action '%s'", optarg);
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
r = sd_device_enumerator_add_match_subsystem(e, optarg, true);
|
||||
if (r < 0)
|
||||
|
||||
@@ -110,3 +110,22 @@ int find_device_with_action(const char *id, sd_device_action_t action, sd_device
|
||||
|
||||
return device_new_from_synthetic_event(ret, id, device_action_to_string(action));
|
||||
}
|
||||
|
||||
int parse_device_action(const char *str, sd_device_action_t *action) {
|
||||
sd_device_action_t a;
|
||||
|
||||
assert(str);
|
||||
assert(action);
|
||||
|
||||
if (streq(str, "help")) {
|
||||
dump_device_action_table();
|
||||
return 0;
|
||||
}
|
||||
|
||||
a = device_action_from_string(str);
|
||||
if (a < 0)
|
||||
return a;
|
||||
|
||||
*action = a;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -5,3 +5,4 @@
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user