X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udevdb.c;h=22d439d6388d0bea47157e799309340bf2aef618;hp=bfd5b4bd697d47e0673d090c2e3494b876f950f7;hb=e4f9c4a46de499841939c51da1a1cf6fd5321bb1;hpb=0bad3406c1e8eba6d5af2cbfd44d8a61231fa2bb diff --git a/udevdb.c b/udevdb.c index bfd5b4bd6..22d439d63 100644 --- a/udevdb.c +++ b/udevdb.c @@ -27,13 +27,14 @@ #define _KLIBC_HAS_ARCH_SIG_ATOMIC_T #include #include +#include #include #include #include #include #include -#include +#include "libsysfs/sysfs/libsysfs.h" #include "udev_version.h" #include "udev.h" #include "logging.h" @@ -53,7 +54,7 @@ int udevdb_add_dev(const char *path, const struct udevice *dev) return -ENODEV; memset(keystr, 0, NAME_SIZE); - strcpy(keystr, path); + strfieldcpy(keystr, path); key.dptr = keystr; key.dsize = strlen(keystr) + 1; @@ -91,7 +92,7 @@ int udevdb_delete_dev(const char *path) return -EINVAL; memset(keystr, 0, sizeof(keystr)); - strcpy(keystr, path); + strfieldcpy(keystr, path); key.dptr = keystr; key.dsize = strlen(keystr) + 1; @@ -178,13 +179,28 @@ static int find_found; static int find_device_by_name(char *path, struct udevice *dev) { + int pos, len; + if (strncmp(dev->name, find_name, sizeof(dev->name)) == 0) { - memcpy(find_dev, dev, sizeof(*find_dev)); - strncpy(find_path, path, NAME_SIZE); + memcpy(find_dev, dev, sizeof(struct udevice)); + strnfieldcpy(find_path, path, NAME_SIZE); find_found = 1; /* stop search */ return 1; } + /* look for matching symlink*/ + foreach_strpart(dev->symlink, " ", pos, len) { + if (strncmp(&dev->symlink[pos], find_name, len) != 0) + continue; + + if (len != strlen(find_name)) + continue; + + memcpy(find_dev, dev, sizeof(struct udevice)); + strnfieldcpy(find_path, path, NAME_SIZE); + find_found = 1; + return 1; + } return 0; }