1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-31 16:21:11 +03:00

pick actual valid device in udev_db_lookup_name

This commit is contained in:
Kay Sievers 2007-03-16 16:02:22 +01:00
parent 2dbb47f860
commit 2afb8cb37a

View File

@ -275,8 +275,7 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len)
while (!found) { while (!found) {
struct dirent *ent; struct dirent *ent;
char device[PATH_SIZE]; char device[PATH_SIZE];
char filename[PATH_SIZE]; struct udevice *udev;
struct stat statbuf;
ent = readdir(dir); ent = readdir(dir);
if (ent == NULL || ent->d_name[0] == '\0') if (ent == NULL || ent->d_name[0] == '\0')
@ -286,15 +285,27 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len)
strlcpy(device, ent->d_name, sizeof(device)); strlcpy(device, ent->d_name, sizeof(device));
path_decode(device); path_decode(device);
udev = udev_device_init();
dbg("looking at '%s'", device); if (udev == NULL)
strlcpy(filename, sysfs_path, sizeof(filename));
strlcat(filename, device, sizeof(filename));
if (stat(filename, &statbuf) == 0) {
strlcpy(devpath, device, len);
found = 1;
break; break;
if (udev_db_get_device(udev, device) == 0) {
char filename[PATH_SIZE];
struct stat statbuf;
info("found db entry '%s'", device);
strlcpy(filename, udev_root, sizeof(filename));
strlcat(filename, "/", sizeof(filename));
strlcat(filename, name, sizeof(filename));
/* make sure device entry matches dev_t */
if (stat(filename, &statbuf) == 0) {
if (statbuf.st_rdev == udev->devt) {
info("node '%s' matches dev_t", udev->name);
strlcpy(devpath, device, len);
found = 1;
}
}
} }
udev_device_cleanup(udev);
} }
closedir(dir); closedir(dir);