mirror of
https://github.com/troglobit/finit.git
synced 2026-11-14 19:03:16 +00:00
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:
2 files changed
+34
-13
No files matched your search
+29
-13
@@ -179,27 +179,26 @@ int udevdb_read(struct uevent *ev)
|
|||||||
* IMPORT{parent} in the rules engine. The parent has no uevent to key
|
* 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()).
|
* 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 subsys[64] = "unknown";
|
||||||
char attr[64];
|
char attr[64];
|
||||||
const char *sn;
|
const char *sn;
|
||||||
char *slash;
|
|
||||||
|
|
||||||
if (!ev->devpath)
|
if (!devpath || *devpath != '/')
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
snprintf(ppath, sizeof(ppath), "%s", ev->devpath);
|
sn = strrchr(devpath, '/');
|
||||||
slash = strrchr(ppath, '/');
|
sn = sn ? sn + 1 : devpath;
|
||||||
if (!slash || slash == ppath)
|
|
||||||
return -1;
|
|
||||||
*slash = 0;
|
|
||||||
|
|
||||||
sn = strrchr(ppath, '/');
|
snprintf(syspath, sizeof(syspath), "/sys%s", devpath);
|
||||||
sn = sn ? sn + 1 : ppath;
|
|
||||||
|
|
||||||
snprintf(syspath, sizeof(syspath), "/sys%s", ppath);
|
|
||||||
sysfs_read_subsystem(syspath, subsys, sizeof(subsys));
|
sysfs_read_subsystem(syspath, subsys, sizeof(subsys));
|
||||||
|
|
||||||
snprintf(dbfile, sizeof(dbfile), "%s/dev", syspath);
|
snprintf(dbfile, sizeof(dbfile), "%s/dev", syspath);
|
||||||
@@ -219,6 +218,23 @@ int udevdb_read_parent(struct uevent *ev)
|
|||||||
return udevdb_load(dbfile, 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.
|
* Remove a device's database entry on ACT_REMOVE.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ int udevdb_read (struct uevent *ev);
|
|||||||
*/
|
*/
|
||||||
int udevdb_read_parent (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.
|
* Delete a device's database entry on ACT_REMOVE.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user