1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-27 18:04:05 +03:00

dissect-image: filter out enumerated or triggered devices without "partition" sysattr

This also adds more filters for device enumerator and monitor.
These newly added filters should be mostly redundant. But this hides
spurious error in sd_device_get_sysattr_value(). See,
https://github.com/systemd/systemd/pull/18684#discussion_r579700977
This commit is contained in:
Yu Watanabe 2021-02-21 11:00:19 +09:00
parent def366933c
commit 210e1cd6e6

View File

@ -127,10 +127,18 @@ static int enumerator_for_parent(sd_device *d, sd_device_enumerator **ret) {
if (r < 0)
return r;
r = sd_device_enumerator_add_match_subsystem(e, "block", true);
if (r < 0)
return r;
r = sd_device_enumerator_add_match_parent(e, d);
if (r < 0)
return r;
r = sd_device_enumerator_add_match_sysattr(e, "partition", NULL, true);
if (r < 0)
return r;
*ret = TAKE_PTR(e);
return 0;
}
@ -151,9 +159,6 @@ static int device_is_partition(sd_device *d, blkid_partition pp) {
return false;
r = sd_device_get_sysattr_value(d, "partition", &v);
if (r == -ENOENT || /* Not a partition device */
ERRNO_IS_PRIVILEGE(r)) /* Not ready to access? */
return false;
if (r < 0)
return r;
r = safe_atoi(v, &partno);
@ -313,6 +318,14 @@ static int wait_for_partition_device(
if (r < 0)
return r;
r = sd_device_monitor_filter_add_match_parent(monitor, parent, true);
if (r < 0)
return r;
r = sd_device_monitor_filter_add_match_sysattr(monitor, "partition", NULL, true);
if (r < 0)
return r;
r = sd_device_monitor_attach_event(monitor, event);
if (r < 0)
return r;