1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

sd-device-enumerator: also move match_parent() to device-util.[ch]

This commit is contained in:
Yu Watanabe 2021-02-21 09:53:50 +09:00
parent d9b030b673
commit bcfe746ba7
3 changed files with 27 additions and 20 deletions

View 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))

View 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;
}

View 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);