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
" --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;
udev_ctrl_unref(uctrl);
return rc;
}
+
+const struct udevadm_cmd udevadm_control = {
+ .name = "control",
+ .cmd = adm_control,
+ .help = "control the udev daemon",
+};
}
}
-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;
udev_device_unref(device);
return rc;
}
+
+const struct udevadm_cmd udevadm_info = {
+ .name = "info",
+ .cmd = uinfo,
+ .help = "query sysfs or the udev database",
+};
}
}
-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;
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",
+};
#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' },
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",
+};
#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];
udev_rules_unref(rules);
return rc;
}
+
+const struct udevadm_cmd udevadm_test = {
+ .name = "test",
+ .cmd = adm_test,
+ .help = "simulation run",
+ .debug = true,
+};
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' },
udev_enumerate_unref(udev_enumerate);
return rc;
}
+
+const struct udevadm_cmd udevadm_trigger = {
+ .name = "trigger",
+ .cmd = adm_trigger,
+ .help = "request events from the kernel",
+};
}
}
-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;
{}
};
const char *command;
- int i;
+ unsigned int i;
int rc = 1;
udev = udev_new();
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;
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);