]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: send udev database version 23817/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 24 Jun 2022 04:05:13 +0000 (13:05 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 8 Jul 2022 19:53:36 +0000 (04:53 +0900)
Otherwise, sd-device object received through sd-device-monitor does not
show current tags.

Fixes #23799.

src/libsystemd/sd-device/device-private.c
src/libsystemd/sd-device/test-sd-device.c

index 90ffd29c574e99066cbe2db3c8f93eb7402f3768..a45389991073c53d54aeef623bc4f3373dd0d11c 100644 (file)
@@ -356,6 +356,10 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
                         if (r < 0)
                                 return log_device_debug_errno(device, r, "sd-device: Failed to add tag '%s': %m", word);
                 }
+        } else if (streq(key, "UDEV_DATABASE_VERSION")) {
+                r = safe_atou(value, &device->database_version);
+                if (r < 0)
+                        return log_device_debug_errno(device, r, "sd-device: Failed to parse udev database version '%s': %m", value);
         } else {
                 r = device_add_property_internal(device, key, value);
                 if (r < 0)
@@ -526,6 +530,15 @@ static int device_update_properties_bufs(sd_device *device) {
         if (!device->properties_buf_outdated)
                 return 0;
 
+        /* append udev database version */
+        buf_nulstr = newdup(char, "UDEV_DATABASE_VERSION=" STRINGIFY(LATEST_UDEV_DATABASE_VERSION) "\0",
+                            STRLEN("UDEV_DATABASE_VERSION=" STRINGIFY(LATEST_UDEV_DATABASE_VERSION)) + 2);
+        if (!buf_nulstr)
+                return -ENOMEM;
+
+        nulstr_len += STRLEN("UDEV_DATABASE_VERSION=" STRINGIFY(LATEST_UDEV_DATABASE_VERSION)) + 1;
+        num++;
+
         FOREACH_DEVICE_PROPERTY(device, prop, val) {
                 size_t len = 0;
 
index 701a68269e4b612159d548260a7b4a1158f0878d..91e358e4645240f888e3c0c3b306072d524e922f 100644 (file)
@@ -334,6 +334,12 @@ TEST(sd_device_new_from_nulstr) {
                 assert_se(set_contains(device->devlinks, devlink));
         }
 
+        /* For issue #23799 */
+        assert_se(device_add_tag(device, "tag1", false) >= 0);
+        assert_se(device_add_tag(device, "tag2", false) >= 0);
+        assert_se(device_add_tag(device, "current-tag1", true) >= 0);
+        assert_se(device_add_tag(device, "current-tag2", true) >= 0);
+
         /* These properties are necessary for device_new_from_nulstr(). See device_verify(). */
         assert_se(device_add_property_internal(device, "SEQNUM", "1") >= 0);
         assert_se(device_add_property_internal(device, "ACTION", "change") >= 0);
@@ -342,6 +348,15 @@ TEST(sd_device_new_from_nulstr) {
         assert_se(nulstr_copy = newdup(char, nulstr, len));
         assert_se(device_new_from_nulstr(&from_nulstr, nulstr_copy, len) >= 0);
 
+        assert_se(sd_device_has_tag(from_nulstr, "tag1") == 1);
+        assert_se(sd_device_has_tag(from_nulstr, "tag2") == 1);
+        assert_se(sd_device_has_tag(from_nulstr, "current-tag1") == 1);
+        assert_se(sd_device_has_tag(from_nulstr, "current-tag2") == 1);
+        assert_se(sd_device_has_current_tag(from_nulstr, "tag1") == 0);
+        assert_se(sd_device_has_current_tag(from_nulstr, "tag2") == 0);
+        assert_se(sd_device_has_current_tag(from_nulstr, "current-tag1") == 1);
+        assert_se(sd_device_has_current_tag(from_nulstr, "current-tag2") == 1);
+
         NULSTR_FOREACH(devlink, devlinks) {
                 log_device_info(from_nulstr, "checking devlink: %s", devlink);
                 assert_se(set_contains(from_nulstr->devlinks, devlink));