summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-09 04:26:15 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-09 21:16:32 +0900
commit0f519b9c2e3ae67e93acc3c2fcfd2945375b69db (patch)
tree73e964675406efcef67b4280f41a91d0d0eaf51e /src/libsystemd
parent539b6597b209dacdf492aa1bd3b55ea6e7f6bb0c (diff)
downloadsystemd-0f519b9c2e3ae67e93acc3c2fcfd2945375b69db.tar.gz
sd-device-enumerator: check sysname earlier
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-device/device-enumerator.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c
index 66845c43a1..3c57cc2f8d 100644
--- a/src/libsystemd/sd-device/device-enumerator.c
+++ b/src/libsystemd/sd-device/device-enumerator.c
@@ -837,7 +837,7 @@ static int enumerator_scan_devices_tags(sd_device_enumerator *enumerator) {
return r;
}
-static int parent_add_child(sd_device_enumerator *enumerator, const char *path) {
+static int parent_add_child(sd_device_enumerator *enumerator, const char *path, MatchFlag flags) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r;
@@ -848,7 +848,7 @@ static int parent_add_child(sd_device_enumerator *enumerator, const char *path)
else if (r < 0)
return r;
- r = test_matches(enumerator, device, MATCH_ALL & (~MATCH_PARENT));
+ r = test_matches(enumerator, device, flags);
if (r <= 0)
return r;
@@ -884,9 +884,13 @@ static int parent_crawl_children(sd_device_enumerator *enumerator, const char *p
if (!child)
return -ENOMEM;
- k = parent_add_child(enumerator, child);
- if (k < 0)
- r = k;
+ /* Let's check sysname filter earlier. The other tests require the sd-device object created
+ * from the path, thus much costly. */
+ if (match_sysname(enumerator, de->d_name)) {
+ k = parent_add_child(enumerator, child, MATCH_ALL & (~(MATCH_SYSNAME|MATCH_PARENT)));
+ if (k < 0)
+ r = k;
+ }
k = set_ensure_consume(stack, &path_hash_ops_free, TAKE_PTR(child));
if (k < 0)
@@ -904,7 +908,7 @@ static int enumerator_scan_devices_children(sd_device_enumerator *enumerator) {
assert(enumerator);
SET_FOREACH(path, enumerator->match_parent) {
- k = parent_add_child(enumerator, path);
+ k = parent_add_child(enumerator, path, MATCH_ALL & (~MATCH_PARENT));
if (k < 0)
r = k;