mirror of
https://github.com/AuxXxilium/eudev.git
synced 2025-01-24 16:10:11 +07:00
sysfs: skip unknown sysfs directories
This commit is contained in:
parent
96d3d86145
commit
fd80719273
20
udev_sysfs.c
20
udev_sysfs.c
@ -155,9 +155,21 @@ struct sysfs_device *sysfs_device_get(const char *devpath)
|
|||||||
int len;
|
int len;
|
||||||
char *pos;
|
char *pos;
|
||||||
|
|
||||||
|
/* we handle only these devpathes */
|
||||||
|
if (devpath != NULL &&
|
||||||
|
strncmp(devpath, "/devices/", 9) != 0 &&
|
||||||
|
strncmp(devpath, "/subsystem/", 11) != 0 &&
|
||||||
|
strncmp(devpath, "/module/", 8) != 0 &&
|
||||||
|
strncmp(devpath, "/bus/", 5) != 0 &&
|
||||||
|
strncmp(devpath, "/class/", 7) != 0 &&
|
||||||
|
strncmp(devpath, "/block/", 7) != 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
dbg("open '%s'", devpath);
|
dbg("open '%s'", devpath);
|
||||||
strlcpy(devpath_real, devpath, sizeof(devpath_real));
|
strlcpy(devpath_real, devpath, sizeof(devpath_real));
|
||||||
remove_trailing_chars(devpath_real, '/');
|
remove_trailing_chars(devpath_real, '/');
|
||||||
|
if (devpath[0] == '\0' )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* look for device already in cache (we never put an untranslated path in the cache) */
|
/* look for device already in cache (we never put an untranslated path in the cache) */
|
||||||
list_for_each_entry(dev_loop, &dev_list, node) {
|
list_for_each_entry(dev_loop, &dev_list, node) {
|
||||||
@ -275,14 +287,6 @@ struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev)
|
|||||||
if (dev->parent != NULL)
|
if (dev->parent != NULL)
|
||||||
return dev->parent;
|
return dev->parent;
|
||||||
|
|
||||||
/* requesting a parent is only valid for these devpathes */
|
|
||||||
if ((strncmp(dev->devpath, "/devices/", 9) != 0) &&
|
|
||||||
(strncmp(dev->devpath, "/subsystem/", 11) != 0) &&
|
|
||||||
(strncmp(dev->devpath, "/bus/", 5) != 0) &&
|
|
||||||
(strncmp(dev->devpath, "/class/", 7) != 0) &&
|
|
||||||
(strncmp(dev->devpath, "/block/", 7) != 0))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
strlcpy(parent_devpath, dev->devpath, sizeof(parent_devpath));
|
strlcpy(parent_devpath, dev->devpath, sizeof(parent_devpath));
|
||||||
dbg("'%s'", parent_devpath);
|
dbg("'%s'", parent_devpath);
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ int main(int argc, char *argv[], char *envp[])
|
|||||||
case ACTION_ATTRIBUTE_WALK:
|
case ACTION_ATTRIBUTE_WALK:
|
||||||
if (path[0] != '\0') {
|
if (path[0] != '\0') {
|
||||||
if (print_device_chain(path) != 0) {
|
if (print_device_chain(path) != 0) {
|
||||||
fprintf(stderr, "device not found\n");
|
fprintf(stderr, "no valid sysfs device found\n");
|
||||||
rc = 4;
|
rc = 4;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -424,7 +424,7 @@ int main(int argc, char *argv[], char *envp[])
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (print_device_chain(udev->dev->devpath) != 0) {
|
if (print_device_chain(udev->dev->devpath) != 0) {
|
||||||
fprintf(stderr, "device not found\n");
|
fprintf(stderr, "no valid sysfs device found\n");
|
||||||
rc = 4;
|
rc = 4;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user