From: Yu Watanabe Date: Sun, 21 Feb 2021 02:00:19 +0000 (+0900) Subject: dissect-image: filter out enumerated or triggered devices without "partition" sysattr X-Git-Tag: v249-rc1~483^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=210e1cd6e6730367d4d104f919047c3decd6b75f;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index fabf3b2e2ec..fb8df16ebc3 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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;