keventd: read udev database records by devpath

udevdb_read_parent() contained the general capability, keyed from
sysfs when no uevent is in hand.  Split it out as
udevdb_read_devpath() for the D-Bus Info method; parent lookup
becomes a wrapper.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-08-16 22:03:43 +02:00
parent 289c1e0de6
commit 6e60b8183a
2 changed files with 34 additions and 13 deletions
+29 -13
View File
@@ -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.
*/
+5
View File
@@ -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.
*/