]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device-enumerator: also move match_parent() to device-util.[ch]
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 21 Feb 2021 00:53:50 +0000 (09:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Apr 2021 06:10:09 +0000 (15:10 +0900)
src/libsystemd/sd-device/device-enumerator.c
src/libsystemd/sd-device/device-util.c
src/libsystemd/sd-device/device-util.h

index 07c0d550650fe229b30dbfd52f205b68dfc2938e..a290dbcc9ce5b17ced396878ad95360cc36a69ce 100644 (file)
@@ -331,24 +331,6 @@ static bool match_tag(sd_device_enumerator *enumerator, sd_device *device) {
         return true;
 }
 
-static bool match_parent(sd_device_enumerator *enumerator, sd_device *device) {
-        const char *syspath_parent, *syspath;
-
-        assert(enumerator);
-        assert(device);
-
-        if (set_isempty(enumerator->match_parent))
-                return true;
-
-        assert_se(sd_device_get_syspath(device, &syspath) >= 0);
-
-        SET_FOREACH(syspath_parent, enumerator->match_parent)
-                if (path_startswith(syspath, syspath_parent))
-                        return true;
-
-        return false;
-}
-
 static bool match_sysname(sd_device_enumerator *enumerator, const char *sysname) {
         const char *sysname_match;
 
@@ -434,7 +416,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
                      sd_device_get_ifindex(device, NULL) >= 0))
                         continue;
 
-                if (!match_parent(enumerator, device))
+                if (!device_match_parent(device, enumerator->match_parent, NULL))
                         continue;
 
                 if (!match_tag(enumerator, device))
@@ -564,7 +546,7 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c
                 if (!match_sysname(enumerator, sysname))
                         continue;
 
-                if (!match_parent(enumerator, device))
+                if (!device_match_parent(device, enumerator->match_parent, NULL))
                         continue;
 
                 if (!match_property(enumerator, device))
index fe495aecf7177feb9d93de64dcbaa7bb1dfdcf7e..616c16c1fc4f47e87aada43e151200b28639ed4c 100644 (file)
@@ -3,6 +3,7 @@
 #include <fnmatch.h>
 
 #include "device-util.h"
+#include "path-util.h"
 
 static bool device_match_sysattr_value(sd_device *device, const char *sysattr, const char *match_value) {
         const char *value;
@@ -38,3 +39,25 @@ bool device_match_sysattr(sd_device *device, Hashmap *match_sysattr, Hashmap *no
 
         return true;
 }
+
+bool device_match_parent(sd_device *device, Set *match_parent, Set *nomatch_parent) {
+        const char *syspath_parent, *syspath;
+
+        assert(device);
+
+        if (sd_device_get_syspath(device, &syspath) < 0)
+                return false;
+
+        SET_FOREACH(syspath_parent, nomatch_parent)
+                if (path_startswith(syspath, syspath_parent))
+                        return false;
+
+        if (set_isempty(match_parent))
+                return true;
+
+        SET_FOREACH(syspath_parent, match_parent)
+                if (path_startswith(syspath, syspath_parent))
+                        return true;
+
+        return false;
+}
index 4dfd8c1dd69ed7639de2fe75375a3feb42a48d6c..026bdcd644caad600c29e5ac9f65642de6699b21 100644 (file)
@@ -8,6 +8,7 @@
 #include "hashmap.h"
 #include "log.h"
 #include "macro.h"
+#include "set.h"
 
 #define FOREACH_DEVICE_PROPERTY(device, key, value)                \
         for (key = sd_device_get_property_first(device, &(value)); \
@@ -72,3 +73,4 @@
 #define log_device_error_errno(device, error, ...)   log_device_full_errno(device, LOG_ERR, error, __VA_ARGS__)
 
 bool device_match_sysattr(sd_device *device, Hashmap *match_sysattr, Hashmap *nomatch_sysattr);
+bool device_match_parent(sd_device *device, Set *match_parent, Set *nomatch_parent);