]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: filter out enumerated or triggered devices without "partition" sysattr
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 21 Feb 2021 02:00:19 +0000 (11:00 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Apr 2021 06:10:09 +0000 (15:10 +0900)
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

src/shared/dissect-image.c

index fabf3b2e2ec025424611ea4f9cf9c12c307bba41..fb8df16ebc3278b84cf5e58bab386f3881b28858 100644 (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;