diff --git a/keventd/udevdb.c b/keventd/udevdb.c index bafe925c..791cf521 100644 --- a/keventd/udevdb.c +++ b/keventd/udevdb.c @@ -179,27 +179,26 @@ int udevdb_read(struct uevent *ev) * IMPORT{parent} in the rules engine. The parent has no uevent to key * from, so its device ID is composed from sysfs (see udevdb_path()). */ -int udevdb_read_parent(struct uevent *ev) +/* + * Read E: records for any devpath, keyed from its sysfs attributes: + * the device has no uevent in hand, so major:minor, ifindex, and + * subsystem come from /sys. Serves IMPORT{parent} and the D-Bus + * Info method. + */ +int udevdb_read_devpath(const char *devpath, struct uevent *ev) { - char ppath[PATH_MAX], syspath[PATH_MAX], dbfile[PATH_MAX]; + char syspath[PATH_MAX], dbfile[PATH_MAX]; char subsys[64] = "unknown"; char attr[64]; const char *sn; - char *slash; - if (!ev->devpath) + if (!devpath || *devpath != '/') return -1; - snprintf(ppath, sizeof(ppath), "%s", ev->devpath); - slash = strrchr(ppath, '/'); - if (!slash || slash == ppath) - return -1; - *slash = 0; + sn = strrchr(devpath, '/'); + sn = sn ? sn + 1 : devpath; - sn = strrchr(ppath, '/'); - sn = sn ? sn + 1 : ppath; - - snprintf(syspath, sizeof(syspath), "/sys%s", ppath); + snprintf(syspath, sizeof(syspath), "/sys%s", devpath); sysfs_read_subsystem(syspath, subsys, sizeof(subsys)); snprintf(dbfile, sizeof(dbfile), "%s/dev", syspath); @@ -219,6 +218,23 @@ int udevdb_read_parent(struct uevent *ev) return udevdb_load(dbfile, ev); } +int udevdb_read_parent(struct uevent *ev) +{ + char ppath[PATH_MAX]; + char *slash; + + if (!ev->devpath) + return -1; + + snprintf(ppath, sizeof(ppath), "%s", ev->devpath); + slash = strrchr(ppath, '/'); + if (!slash || slash == ppath) + return -1; + *slash = 0; + + return udevdb_read_devpath(ppath, ev); +} + /* * Remove a device's database entry on ACT_REMOVE. */ diff --git a/keventd/udevdb.h b/keventd/udevdb.h index 037eabbc..ec4f1ea9 100644 --- a/keventd/udevdb.h +++ b/keventd/udevdb.h @@ -57,6 +57,11 @@ int udevdb_read (struct uevent *ev); */ int udevdb_read_parent (struct uevent *ev); +/* + * Like udevdb_read(), for any devpath, keyed from sysfs. + */ +int udevdb_read_devpath(const char *devpath, struct uevent *ev); + /* * Delete a device's database entry on ACT_REMOVE. */