diff options
Diffstat (limited to 'udev')
-rw-r--r-- | udev/udev.h | 18 | ||||
-rw-r--r-- | udev/udevadm-control.c | 8 | ||||
-rw-r--r-- | udev/udevadm-info.c | 8 | ||||
-rw-r--r-- | udev/udevadm-monitor.c | 8 | ||||
-rw-r--r-- | udev/udevadm-settle.c | 8 | ||||
-rw-r--r-- | udev/udevadm-test.c | 9 | ||||
-rw-r--r-- | udev/udevadm-trigger.c | 8 | ||||
-rw-r--r-- | udev/udevadm.c | 101 |
8 files changed, 90 insertions, 78 deletions
diff --git a/udev/udev.h b/udev/udev.h index 0a693e4608..0c73b502cb 100644 --- a/udev/udev.h +++ b/udev/udev.h @@ -129,10 +129,16 @@ const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg); int udev_ctrl_get_set_children_max(struct udev_ctrl_msg *ctrl_msg); /* udevadm commands */ -int udevadm_monitor(struct udev *udev, int argc, char *argv[]); -int udevadm_info(struct udev *udev, int argc, char *argv[]); -int udevadm_control(struct udev *udev, int argc, char *argv[]); -int udevadm_trigger(struct udev *udev, int argc, char *argv[]); -int udevadm_settle(struct udev *udev, int argc, char *argv[]); -int udevadm_test(struct udev *udev, int argc, char *argv[]); +struct udevadm_cmd { + const char *name; + int (*cmd)(struct udev *udev, int argc, char *argv[]); + const char *help; + int debug; +}; +extern const struct udevadm_cmd udevadm_monitor; +extern const struct udevadm_cmd udevadm_info; +extern const struct udevadm_cmd udevadm_control; +extern const struct udevadm_cmd udevadm_trigger; +extern const struct udevadm_cmd udevadm_settle; +extern const struct udevadm_cmd udevadm_test; #endif diff --git a/udev/udevadm-control.c b/udev/udevadm-control.c index 69da86563d..b500d75a4e 100644 --- a/udev/udevadm-control.c +++ b/udev/udevadm-control.c @@ -41,7 +41,7 @@ static void print_help(void) " --help print this help text\n\n"); } -int udevadm_control(struct udev *udev, int argc, char *argv[]) +static int adm_control(struct udev *udev, int argc, char *argv[]) { struct udev_ctrl *uctrl = NULL; int timeout = 60; @@ -161,3 +161,9 @@ out: udev_ctrl_unref(uctrl); return rc; } + +const struct udevadm_cmd udevadm_control = { + .name = "control", + .cmd = adm_control, + .help = "control the udev daemon", +}; diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c index a6387d07ae..4053436fe6 100644 --- a/udev/udevadm-info.c +++ b/udev/udevadm-info.c @@ -275,7 +275,7 @@ static void cleanup_db(struct udev *udev) } } -int udevadm_info(struct udev *udev, int argc, char *argv[]) +static int uinfo(struct udev *udev, int argc, char *argv[]) { struct udev_device *device = NULL; bool root = 0; @@ -556,3 +556,9 @@ exit: udev_device_unref(device); return rc; } + +const struct udevadm_cmd udevadm_info = { + .name = "info", + .cmd = uinfo, + .help = "query sysfs or the udev database", +}; diff --git a/udev/udevadm-monitor.c b/udev/udevadm-monitor.c index 9b8bf4eccf..7ea7aa0f70 100644 --- a/udev/udevadm-monitor.c +++ b/udev/udevadm-monitor.c @@ -64,7 +64,7 @@ static void print_device(struct udev_device *device, const char *source, int pro } } -int udevadm_monitor(struct udev *udev, int argc, char *argv[]) +static int adm_monitor(struct udev *udev, int argc, char *argv[]) { struct sigaction act; sigset_t mask; @@ -289,3 +289,9 @@ out: udev_list_cleanup_entries(udev, &tag_match_list); return rc; } + +const struct udevadm_cmd udevadm_monitor = { + .name = "monitor", + .cmd = adm_monitor, + .help = "listen to kernel and udev events", +}; diff --git a/udev/udevadm-settle.c b/udev/udevadm-settle.c index b17ba806d0..d40c8c8d5e 100644 --- a/udev/udevadm-settle.c +++ b/udev/udevadm-settle.c @@ -36,7 +36,7 @@ #include "udev.h" -int udevadm_settle(struct udev *udev, int argc, char *argv[]) +static int adm_settle(struct udev *udev, int argc, char *argv[]) { static const struct option options[] = { { "seq-start", required_argument, NULL, 's' }, @@ -225,3 +225,9 @@ out: udev_queue_unref(udev_queue); return rc; } + +const struct udevadm_cmd udevadm_settle = { + .name = "settle", + .cmd = adm_settle, + .help = "wait for the event queue to finish", +}; diff --git a/udev/udevadm-test.c b/udev/udevadm-test.c index bb7a0fd8a1..c2c377c3d7 100644 --- a/udev/udevadm-test.c +++ b/udev/udevadm-test.c @@ -31,7 +31,7 @@ #include "udev.h" -int udevadm_test(struct udev *udev, int argc, char *argv[]) +static int adm_test(struct udev *udev, int argc, char *argv[]) { int resolve_names = 1; char filename[UTIL_PATH_SIZE]; @@ -161,3 +161,10 @@ out: udev_rules_unref(rules); return rc; } + +const struct udevadm_cmd udevadm_test = { + .name = "test", + .cmd = adm_test, + .help = "simulation run", + .debug = true, +}; diff --git a/udev/udevadm-trigger.c b/udev/udevadm-trigger.c index 3b53be5646..610cf5e9c1 100644 --- a/udev/udevadm-trigger.c +++ b/udev/udevadm-trigger.c @@ -89,7 +89,7 @@ static const char *keyval(const char *str, const char **val, char *buf, size_t s return buf; } -int udevadm_trigger(struct udev *udev, int argc, char *argv[]) +static int adm_trigger(struct udev *udev, int argc, char *argv[]) { static const struct option options[] = { { "verbose", no_argument, NULL, 'v' }, @@ -247,3 +247,9 @@ exit: udev_enumerate_unref(udev_enumerate); return rc; } + +const struct udevadm_cmd udevadm_trigger = { + .name = "trigger", + .cmd = adm_trigger, + .help = "request events from the kernel", +}; diff --git a/udev/udevadm.c b/udev/udevadm.c index 2a29158917..d3810e73e0 100644 --- a/udev/udevadm.c +++ b/udev/udevadm.c @@ -44,77 +44,46 @@ static void log_fn(struct udev *udev, int priority, } } -struct command { - const char *name; - int (*cmd)(struct udev *udev, int argc, char *argv[]); - const char *help; - int debug; -}; - -static const struct command cmds[]; - -static int version(struct udev *udev, int argc, char *argv[]) +static int adm_version(struct udev *udev, int argc, char *argv[]) { printf("%s\n", VERSION); return 0; } +static const struct udevadm_cmd udevadm_version = { + .name = "version", + .cmd = adm_version, +}; + +static int adm_help(struct udev *udev, int argc, char *argv[]); +static const struct udevadm_cmd udevadm_help = { + .name = "help", + .cmd = adm_help, +}; + +static const struct udevadm_cmd *udevadm_cmds[] = { + &udevadm_info, + &udevadm_trigger, + &udevadm_settle, + &udevadm_control, + &udevadm_monitor, + &udevadm_test, + &udevadm_version, + &udevadm_help, +}; -static int help(struct udev *udev, int argc, char *argv[]) +static int adm_help(struct udev *udev, int argc, char *argv[]) { - const struct command *cmd; + unsigned int i; printf("Usage: udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n"); - for (cmd = cmds; cmd->name != NULL; cmd++) - if (cmd->help != NULL) - printf(" %-12s %s\n", cmd->name, cmd->help); + for (i = 0; i < ARRAY_SIZE(udevadm_cmds); i++) + if (udevadm_cmds[i]->help != NULL) + printf(" %-12s %s\n", udevadm_cmds[i]->name, udevadm_cmds[i]->help); printf("\n"); return 0; } -static const struct command cmds[] = { - { - .name = "info", - .cmd = udevadm_info, - .help = "query sysfs or the udev database", - }, - { - .name = "trigger", - .cmd = udevadm_trigger, - .help = "request events from the kernel", - }, - { - .name = "settle", - .cmd = udevadm_settle, - .help = "wait for the event queue to finish", - }, - { - .name = "control", - .cmd = udevadm_control, - .help = "control the udev daemon", - }, - { - .name = "monitor", - .cmd = udevadm_monitor, - .help = "listen to kernel and udev events", - }, - { - .name = "test", - .cmd = udevadm_test, - .help = "simulation run", - .debug = true, - }, - { - .name = "version", - .cmd = version, - }, - { - .name = "help", - .cmd = help, - }, - {} -}; - -static int run_command(struct udev *udev, const struct command *cmd, int argc, char *argv[]) +static int run_command(struct udev *udev, const struct udevadm_cmd *cmd, int argc, char *argv[]) { if (cmd->debug) { debug = true; @@ -135,7 +104,7 @@ int main(int argc, char *argv[]) {} }; const char *command; - int i; + unsigned int i; int rc = 1; udev = udev_new(); @@ -160,10 +129,10 @@ int main(int argc, char *argv[]) udev_set_log_priority(udev, LOG_INFO); break; case 'h': - rc = help(udev, argc, argv); + rc = adm_help(udev, argc, argv); goto out; case 'V': - rc = version(udev, argc, argv); + rc = adm_version(udev, argc, argv); goto out; default: goto out; @@ -174,18 +143,18 @@ int main(int argc, char *argv[]) info(udev, "runtime dir '%s'\n", udev_get_run_path(udev)); if (command != NULL) - for (i = 0; cmds[i].cmd != NULL; i++) { - if (strcmp(cmds[i].name, command) == 0) { + for (i = 0; i < ARRAY_SIZE(udevadm_cmds); i++) { + if (strcmp(udevadm_cmds[i]->name, command) == 0) { argc -= optind; argv += optind; optind = 0; - rc = run_command(udev, &cmds[i], argc, argv); + rc = run_command(udev, udevadm_cmds[i], argc, argv); goto out; } } fprintf(stderr, "missing or unknown command\n\n"); - help(udev, argc, argv); + adm_help(udev, argc, argv); rc = 2; out: udev_selinux_exit(udev); |