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().
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+8
-10
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user