- if (command == NULL)
- goto err_unknown;
-
- /* allow command to be specified as an option */
- if (strncmp(command, "--", 2) == 0)
- command += 2;
-
- /* find and execute command */
- for (cmd = cmds; cmd->name != NULL; cmd++) {
- if (strcmp(cmd->name, command) == 0) {
- debug = cmd->debug;
- rc = cmd->cmd(argc, argv, envp);
+int main(int argc, char *argv[])
+{
+ struct udev *udev;
+ static const struct option options[] = {
+ { "debug", no_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'V' },
+ {}
+ };
+ const char *command;
+ int i;
+ int rc = 1;
+
+ udev = udev_new();
+ if (udev == NULL)
+ goto out;
+
+ udev_log_init("udevadm");
+ udev_set_log_fn(udev, log_fn);
+ udev_selinux_init(udev);
+
+ while (1) {
+ int option;
+
+ option = getopt_long(argc, argv, "+dhV", options, NULL);
+ if (option == -1)
+ break;
+
+ switch (option) {
+ case 'd':
+ debug = 1;
+ if (udev_get_log_priority(udev) < LOG_INFO)
+ udev_set_log_priority(udev, LOG_INFO);
+ break;
+ case 'h':
+ rc = help(udev, argc, argv);
+ goto out;
+ case 'V':
+ rc = version(udev, argc, argv);
+ goto out;
+ default: