]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: make sd_device_has_current_tag() and friends compatible with database... 17622/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Nov 2020 10:47:42 +0000 (19:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 25 Nov 2020 23:29:17 +0000 (08:29 +0900)
src/libsystemd/sd-device/sd-device.c

index 1b07f528f291ad25e88ce2e359bf6f434d730439..d06f90ce1d881348499b28cf7bb0cf17a584d753 100644 (file)
@@ -1444,11 +1444,26 @@ _public_ const char *sd_device_get_tag_next(sd_device *device) {
         return v;
 }
 
+static bool device_database_supports_current_tags(sd_device *device) {
+        assert(device);
+
+        (void) device_read_db(device);
+
+        /* The current tags (saved in Q field) feature is implemented in database version 1.
+         * If the database version is 0, then the tags (NOT current tags, saved in G field) are not
+         * sticky. Thus, we can safely bypass the operations for the current tags (Q) to tags (G). */
+
+        return device->database_version >= 1;
+}
+
 _public_ const char *sd_device_get_current_tag_first(sd_device *device) {
         void *v;
 
         assert_return(device, NULL);
 
+        if (!device_database_supports_current_tags(device))
+                return sd_device_get_tag_first(device);
+
         (void) device_read_db(device);
 
         device->current_tags_iterator_generation = device->tags_generation;
@@ -1463,6 +1478,9 @@ _public_ const char *sd_device_get_current_tag_next(sd_device *device) {
 
         assert_return(device, NULL);
 
+        if (!device_database_supports_current_tags(device))
+                return sd_device_get_tag_next(device);
+
         (void) device_read_db(device);
 
         if (device->current_tags_iterator_generation != device->tags_generation)
@@ -1765,6 +1783,9 @@ _public_ int sd_device_has_current_tag(sd_device *device, const char *tag) {
         assert_return(device, -EINVAL);
         assert_return(tag, -EINVAL);
 
+        if (!device_database_supports_current_tags(device))
+                return sd_device_has_tag(device, tag);
+
         (void) device_read_db(device);
 
         return set_contains(device->current_tags, tag);