- /* remove /sys if given */
- if (strncmp(optarg, sysfs_path, strlen(sysfs_path)) == 0)
- strlcpy(path, &optarg[strlen(sysfs_path)], sizeof(path));
- else
- strlcpy(path, optarg, sizeof(path));
- remove_trailing_chars(path, '/');
-
- /* possibly resolve to real devpath */
- if (sysfs_resolve_link(path, sizeof(path)) != 0) {
- char temp[PATH_SIZE];
- char *pos;
-
- /* also check if the parent is a link */
- strlcpy(temp, path, sizeof(temp));
- pos = strrchr(temp, '/');
- if (pos != 0) {
- char tail[PATH_SIZE];
-
- strlcpy(tail, pos, sizeof(tail));
- pos[0] = '\0';
- if (sysfs_resolve_link(temp, sizeof(temp)) == 0) {
- strlcpy(path, temp, sizeof(path));
- strlcat(path, tail, sizeof(path));
- }
- }
+ if (device != NULL) {
+ fprintf(stderr, "device already specified\n");
+ rc = 2;
+ goto exit;
+ }
+ /* add /sys if needed */
+ if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
+ util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
+ util_strlcat(path, optarg, sizeof(path));
+ } else {
+ util_strlcpy(path, optarg, sizeof(path));
+ }
+ util_remove_trailing_chars(path, '/');
+ device = udev_device_new_from_syspath(udev, path);
+ if (device == NULL) {
+ fprintf(stderr, "device path not found\n");
+ rc = 2;
+ goto exit;