summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-04-22 19:01:50 +0200
committerTom Gundersen <teg@jklm.no>2015-04-23 22:31:25 +0200
commit378f61ebef6d29efce8512402a73df880c7d960c (patch)
tree41364b99a5d3bdeeb44face1226e68fec4d80233
parent4761e880aea33d06be9c6f198e4dcf5efb3baa9e (diff)
libudev-device: fix lazy loading of devlinks, properties and tags
If the underlying device has not read in the properties yet, the generation will be 0, so make sure we trigger the reading at least once.
-rw-r--r--src/libudev/libudev-device-internal.h3
-rw-r--r--src/libudev/libudev-device.c12
2 files changed, 12 insertions, 3 deletions
diff --git a/src/libudev/libudev-device-internal.h b/src/libudev/libudev-device-internal.h
index 3f93fda545..aa36b8cb12 100644
--- a/src/libudev/libudev-device-internal.h
+++ b/src/libudev/libudev-device-internal.h
@@ -47,6 +47,9 @@ struct udev_device {
uint64_t tags_generation;
struct udev_list devlinks;
uint64_t devlinks_generation;
+ bool properties_read:1;
+ bool tags_read:1;
+ bool devlinks_read:1;
struct udev_list sysattrs;
bool sysattrs_read;
};
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index a55cd258f4..893d72c19f 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -700,7 +700,8 @@ _public_ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev
{
assert_return_errno(udev_device, NULL, EINVAL);
- if (device_get_devlinks_generation(udev_device->device) != udev_device->devlinks_generation) {
+ if (device_get_devlinks_generation(udev_device->device) != udev_device->devlinks_generation ||
+ !udev_device->devlinks_read) {
const char *devlink;
udev_list_cleanup(&udev_device->devlinks);
@@ -708,6 +709,7 @@ _public_ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev
FOREACH_DEVICE_DEVLINK(udev_device->device, devlink)
udev_list_entry_add(&udev_device->devlinks, devlink, NULL);
+ udev_device->devlinks_read = true;
udev_device->devlinks_generation = device_get_devlinks_generation(udev_device->device);
}
@@ -730,7 +732,8 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud
{
assert_return_errno(udev_device, NULL, EINVAL);
- if (device_get_properties_generation(udev_device->device) != udev_device->properties_generation) {
+ if (device_get_properties_generation(udev_device->device) != udev_device->properties_generation ||
+ !udev_device->properties_read) {
const char *key, *value;
udev_list_cleanup(&udev_device->properties);
@@ -738,6 +741,7 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud
FOREACH_DEVICE_PROPERTY(udev_device->device, key, value)
udev_list_entry_add(&udev_device->properties, key, value);
+ udev_device->properties_read = true;
udev_device->properties_generation = device_get_properties_generation(udev_device->device);
}
@@ -918,7 +922,8 @@ _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_dev
{
assert_return_errno(udev_device, NULL, EINVAL);
- if (device_get_tags_generation(udev_device->device) != udev_device->tags_generation) {
+ if (device_get_tags_generation(udev_device->device) != udev_device->tags_generation ||
+ !udev_device->tags_read) {
const char *tag;
udev_list_cleanup(&udev_device->tags);
@@ -926,6 +931,7 @@ _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_dev
FOREACH_DEVICE_TAG(udev_device->device, tag)
udev_list_entry_add(&udev_device->tags, tag, NULL);
+ udev_device->tags_read = true;
udev_device->tags_generation = device_get_tags_generation(udev_device->device);
}