- const char *pos;
- const struct command *cmd;
- int rc;
-
- /* get binary or symlink name */
- pos = strrchr(argv[0], '/');
- if (pos != NULL)
- command = &pos[1];
- else
- command = argv[0];
-
- /* the trailing part of the binary or symlink name is the command */
- if (strncmp(command, "udev", 4) == 0)
- command = &command[4];
-
- if (command == NULL || command[0] == '\0')
- goto err_unknown;
-
- /* udevadm itself needs to strip its name from the passed options */
- if (strcmp(command, "adm") == 0) {
- command = argv[1];
- argv++;
- argc--;
- }
-
- 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);
+ unsigned 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);
+
+ for (;;) {
+ int option;
+
+ option = getopt_long(argc, argv, "+dhV", options, NULL);
+ if (option == -1)
+ break;
+
+ switch (option) {
+ case 'd':
+ debug = true;
+ if (udev_get_log_priority(udev) < LOG_INFO)
+ udev_set_log_priority(udev, LOG_INFO);
+ break;
+ case 'h':
+ rc = adm_help(udev, argc, argv);
+ goto out;
+ case 'V':
+ rc = adm_version(udev, argc, argv);
+ goto out;
+ default: