]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libudev: also expose API to check for current tags in libudev
authorLennart Poettering <lennart@poettering.net>
Thu, 13 Dec 2018 17:08:45 +0000 (18:08 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 1 Sep 2020 15:40:12 +0000 (17:40 +0200)
meson.build
src/libudev/libudev-device.c
src/libudev/libudev.h
src/libudev/libudev.sym

index 683754031383d055f6366c357d64a35b2b68dc11..217b17423bc109c44f68373a10f03babebb147d4 100644 (file)
@@ -14,7 +14,7 @@ project('systemd', 'c',
        )
 
 libsystemd_version = '0.29.0'
-libudev_version = '1.6.18'
+libudev_version = '1.7.0'
 
 # We need the same data in two different formats, ugh!
 # Also, for hysterical reasons, we use different variable
index b993309911314a7b557bb34f7465d8dc23d252b0..704a09d01cd59b7f67e122926c4b9e871b3c063d 100644 (file)
@@ -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);
 
index 02c2e5e8eda3b1e1ae2a7d6431d506c5836f214b..c9d0bf233e506a27919754183ed678b4215011c5 100644 (file)
@@ -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
index fb2e03e432d4f776f214081da6c47f4faeddb5eb..bad8313904398f09b8a537250cf534737f6847fc 100644 (file)
@@ -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;