Skip to content
Snippets Groups Projects
Commit 340f11d2 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

refactor and remove some now redundant code

parent 40a0b8e3
Branches
No related tags found
No related merge requests found
......@@ -466,15 +466,13 @@ fail_dr:
int get_devices(void)
{
char usb_path[PATH_MAX], product_path[PATH_MAX], path[PATH_MAX], *name;
char devices_path[PATH_MAX], mount_path[PATH_MAX];
struct dirent *de;
DIR *dir;
struct stat st;
struct device *dev;
int rv;
strncpy(usb_path, "/sys/bus/usb/devices/", PATH_MAX);
dir = opendir(usb_path);
strncpy(devices_path, "/sys/bus/usb/devices/", PATH_MAX);
dir = opendir(devices_path);
if (!dir) {
perror("opendir");
goto fail_dr;
......@@ -485,38 +483,14 @@ int get_devices(void)
continue;
if (strstr(de->d_name, ":") || strstr(de->d_name, "usb"))
continue;
snprintf(product_path, PATH_MAX, "%s%s/product", usb_path, de->d_name);
memset(&st, 0, sizeof(st));
rv = stat(product_path, &st);
if (rv < 0) {
//perror("stat");
continue;
}
snprintf(path, PATH_MAX, "%s%s/", usb_path, de->d_name);
name = get_device_name(path);
if (!name)
continue;
dev = (struct device *)calloc(1, sizeof(*dev));
if (!dev) {
perror("calloc");
goto fail_dev;
}
dev->usb.product = get_usb_stat(path, "product");
dev->usb.product_id = get_usb_stat(path, "idProduct");
dev->usb.vendor_id = get_usb_stat(path, "idVendor");
dev->usb.if_name = name;
dev->ip = get_device_ip(dev->usb.if_name);
add_device(dev);
snprintf(mount_path, PATH_MAX, "%s%s/", devices_path, de->d_name);
rv = get_devices_from_path(mount_path);
if (rv < 0)
break;
}
closedir(dir);
return 0;
fail_dev:
closedir(dir);
fail_dr:
return -1;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment