]> err.no Git - systemd/commitdiff
udevadm: move udevadm command descriptions into their files
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 13 Jul 2011 23:53:23 +0000 (01:53 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 13 Jul 2011 23:53:23 +0000 (01:53 +0200)
udev/udev.h
udev/udevadm-control.c
udev/udevadm-info.c
udev/udevadm-monitor.c
udev/udevadm-settle.c
udev/udevadm-test.c
udev/udevadm-trigger.c
udev/udevadm.c

index 0a693e460827572ffaee464b256c4c893d5335bd..0c73b502cb60f885336ef05e970532b2015de6d3 100644 (file)
@@ -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
index 69da86563de6fb4f2038d2d47bbbde6ccb66f702..b500d75a4e20b5d6d18ad3c1f892d1b9868bc73a 100644 (file)
@@ -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",
+};
index a6387d07aecaa11c8e0b2456c644332f85421348..4053436fe64624634a8f15bcbd0907ac543a7bd7 100644 (file)
@@ -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",
+};
index 9b8bf4eccf50c31b84ef61a3903c014a083aa9e3..7ea7aa0f7067f76ba470036bb0f84b8714494584 100644 (file)
@@ -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",
+};
index b17ba806d00a7ec33b79f002adcd91ec7d593cff..d40c8c8d5e05c9503537f021f99eac71f525bfda 100644 (file)
@@ -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",
+};
index bb7a0fd8a1a4b9bd83c46ad98286dce8f3e19ea5..c2c377c3d7d2c2ba91910e0592a0b8de36fefa04 100644 (file)
@@ -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,
+};
index 3b53be564640dfefeb170a63079e7db2a0028148..610cf5e9c17972015af24ccc33f6922fac413a7d 100644 (file)
@@ -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",
+};
index 2a2915891797dcba2b17940ed7db701722b7e7e4..d3810e73e05768f5fbc95417e6822863de293a66 100644 (file)
@@ -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);