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;
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))
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))
#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;
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;
+}
#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)); \
#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);