diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-12-13 18:08:45 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-09-01 17:40:12 +0200 |
commit | 3b684be04b95bd5264dff0f2af343c52b4dba86b (patch) | |
tree | 1f814223f9afbe1908957195f54d39343c8dc9e4 /src | |
parent | udev: make tags "sticky" (diff) | |
download | systemd-3b684be04b95bd5264dff0f2af343c52b4dba86b.tar.xz systemd-3b684be04b95bd5264dff0f2af343c52b4dba86b.zip |
libudev: also expose API to check for current tags in libudev
Diffstat (limited to 'src')
-rw-r--r-- | src/libudev/libudev-device.c | 62 | ||||
-rw-r--r-- | src/libudev/libudev.h | 2 | ||||
-rw-r--r-- | src/libudev/libudev.sym | 6 |
3 files changed, 55 insertions, 15 deletions
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index b993309911..704a09d01c 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -56,12 +56,13 @@ struct udev_device { struct udev_list *properties; uint64_t properties_generation; - struct udev_list *tags; - uint64_t tags_generation; + struct udev_list *all_tags, *current_tags; + uint64_t all_tags_generation, current_tags_generation; struct udev_list *devlinks; uint64_t devlinks_generation; bool properties_read:1; - bool tags_read:1; + bool all_tags_read:1; + bool current_tags_read:1; bool devlinks_read:1; struct udev_list *sysattrs; bool sysattrs_read; @@ -199,7 +200,7 @@ _public_ const char *udev_device_get_property_value(struct udev_device *udev_dev } struct udev_device *udev_device_new(struct udev *udev, sd_device *device) { - _cleanup_(udev_list_freep) struct udev_list *properties = NULL, *tags = NULL, *sysattrs = NULL, *devlinks = NULL; + _cleanup_(udev_list_freep) struct udev_list *properties = NULL, *all_tags = NULL, *current_tags = NULL, *sysattrs = NULL, *devlinks = NULL; struct udev_device *udev_device; assert(device); @@ -207,8 +208,11 @@ struct udev_device *udev_device_new(struct udev *udev, sd_device *device) { properties = udev_list_new(true); if (!properties) return_with_errno(NULL, ENOMEM); - tags = udev_list_new(true); - if (!tags) + all_tags = udev_list_new(true); + if (!all_tags) + return_with_errno(NULL, ENOMEM); + current_tags = udev_list_new(true); + if (!current_tags) return_with_errno(NULL, ENOMEM); sysattrs = udev_list_new(true); if (!sysattrs) @@ -226,7 +230,8 @@ struct udev_device *udev_device_new(struct udev *udev, sd_device *device) { .udev = udev, .device = sd_device_ref(device), .properties = TAKE_PTR(properties), - .tags = TAKE_PTR(tags), + .all_tags = TAKE_PTR(all_tags), + .current_tags = TAKE_PTR(current_tags), .sysattrs = TAKE_PTR(sysattrs), .devlinks = TAKE_PTR(devlinks), }; @@ -475,7 +480,8 @@ static struct udev_device *udev_device_free(struct udev_device *udev_device) { udev_list_free(udev_device->properties); udev_list_free(udev_device->sysattrs); - udev_list_free(udev_device->tags); + udev_list_free(udev_device->all_tags); + udev_list_free(udev_device->current_tags); udev_list_free(udev_device->devlinks); return mfree(udev_device); @@ -834,21 +840,41 @@ _public_ int udev_device_get_is_initialized(struct udev_device *udev_device) { _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device) { assert_return_errno(udev_device, NULL, EINVAL); - if (device_get_tags_generation(udev_device->device) != udev_device->tags_generation || - !udev_device->tags_read) { + if (device_get_tags_generation(udev_device->device) != udev_device->all_tags_generation || + !udev_device->all_tags_read) { const char *tag; - udev_list_cleanup(udev_device->tags); + udev_list_cleanup(udev_device->all_tags); FOREACH_DEVICE_TAG(udev_device->device, tag) - if (!udev_list_entry_add(udev_device->tags, tag, NULL)) + if (!udev_list_entry_add(udev_device->all_tags, tag, NULL)) + return_with_errno(NULL, ENOMEM); + + udev_device->all_tags_read = true; + udev_device->all_tags_generation = device_get_tags_generation(udev_device->device); + } + + return udev_list_get_entry(udev_device->all_tags); +} + +_public_ struct udev_list_entry *udev_device_get_current_tags_list_entry(struct udev_device *udev_device) { + assert_return_errno(udev_device, NULL, EINVAL); + + if (device_get_tags_generation(udev_device->device) != udev_device->current_tags_generation || + !udev_device->current_tags_read) { + const char *tag; + + udev_list_cleanup(udev_device->current_tags); + + FOREACH_DEVICE_CURRENT_TAG(udev_device->device, tag) + if (!udev_list_entry_add(udev_device->current_tags, tag, NULL)) return_with_errno(NULL, ENOMEM); - udev_device->tags_read = true; - udev_device->tags_generation = device_get_tags_generation(udev_device->device); + udev_device->current_tags_read = true; + udev_device->current_tags_generation = device_get_tags_generation(udev_device->device); } - return udev_list_get_entry(udev_device->tags); + return udev_list_get_entry(udev_device->current_tags); } /** @@ -866,6 +892,12 @@ _public_ int udev_device_has_tag(struct udev_device *udev_device, const char *ta return sd_device_has_tag(udev_device->device, tag) > 0; } +_public_ int udev_device_has_current_tag(struct udev_device *udev_device, const char *tag) { + assert_return(udev_device, 0); + + return sd_device_has_current_tag(udev_device->device, tag) > 0; +} + sd_device *udev_device_get_sd_device(struct udev_device *udev_device) { assert(udev_device); diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index 02c2e5e8ed..c9d0bf233e 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -82,6 +82,7 @@ int udev_device_get_is_initialized(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device); +struct udev_list_entry *udev_device_get_current_tags_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device); const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key); const char *udev_device_get_driver(struct udev_device *udev_device); @@ -92,6 +93,7 @@ unsigned long long int udev_device_get_usec_since_initialized(struct udev_device const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr); int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, const char *value); int udev_device_has_tag(struct udev_device *udev_device, const char *tag); +int udev_device_has_current_tag(struct udev_device *udev_device, const char *tag); /* * udev_monitor diff --git a/src/libudev/libudev.sym b/src/libudev/libudev.sym index fb2e03e432..bad8313904 100644 --- a/src/libudev/libudev.sym +++ b/src/libudev/libudev.sym @@ -118,3 +118,9 @@ global: udev_queue_flush; udev_queue_get_fd; } LIBUDEV_199; + +LIBUDEV_247 { +global: + udev_device_has_current_tag; + udev_device_get_current_tags_list_entry; +} LIBUDEV_215; |