mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
sd-device: send udev database version
Otherwise, sd-device object received through sd-device-monitor does not
show current tags.
Fixes #23799.
(cherry picked from commit 4bc4040bc0
)
This commit is contained in:
parent
925cff4a15
commit
7f80102343
@ -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;
|
||||
|
||||
|
@ -331,6 +331,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);
|
||||
@ -339,6 +345,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));
|
||||
|
Loading…
Reference in New Issue
Block a user