X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udevdb.c;h=f2469367109870009786cd6f5241c246ada8fafb;hp=e657fedcb2018ec8b67ac310f42ee85eb23f5482;hb=9b28a52a0ac9b7993c932bbfe9d86dfc814be218;hpb=00866ed2a1f755eb027c84827fed1ed77364d436 diff --git a/udevdb.c b/udevdb.c index e657fedcb..f24693671 100644 --- a/udevdb.c +++ b/udevdb.c @@ -1,5 +1,5 @@ /* - * udevdb.c + * udevdb.c - udev database library * * Userspace devfs * @@ -21,25 +21,25 @@ * */ -/* - * udev database library - */ #define _KLIBC_HAS_ARCH_SIG_ATOMIC_T #include #include +#include +#include #include #include #include #include #include -#include "udev_version.h" +#include "libsysfs/sysfs/libsysfs.h" #include "udev.h" +#include "udev_lib.h" +#include "udev_version.h" #include "logging.h" #include "namedev.h" #include "udevdb.h" #include "tdb/tdb.h" -#include "libsysfs/libsysfs.h" static TDB_CONTEXT *udevdb; @@ -53,12 +53,13 @@ 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; data.dptr = (void *)dev; data.dsize = UDEVICE_LEN; + dbg("store key '%s' for device '%s'", path, dev->name); return tdb_store(udevdb, key, data, TDB_REPLACE); } @@ -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,29 @@ static int find_found; static int find_device_by_name(char *path, struct udevice *dev) { + char *pos; + int 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)); + strfieldcpymax(find_path, path, NAME_SIZE); find_found = 1; /* stop search */ return 1; } + /* look for matching symlink*/ + foreach_strpart(dev->symlink, " ", pos, len) { + if (strncmp(pos, find_name, len) != 0) + continue; + + if (len != strlen(find_name)) + continue; + + memcpy(find_dev, dev, sizeof(struct udevice)); + strfieldcpymax(find_path, path, NAME_SIZE); + find_found = 1; + return 1; + } return 0; }