It will be used by sd-device-monitor in later commits.
sd-device/device-monitor.c
sd-device/device-private.c
sd-device/device-private.h
+ sd-device/device-util.c
sd-device/device-util.h
sd-device/sd-device.c
sd-hwdb/hwdb-internal.h
return 0;
}
-static bool match_sysattr_value(sd_device *device, const char *sysattr, const char *match_value) {
- const char *value;
-
- assert(device);
- assert(sysattr);
-
- if (sd_device_get_sysattr_value(device, sysattr, &value) < 0)
- return false;
-
- if (!match_value)
- return true;
-
- if (fnmatch(match_value, value, 0) == 0)
- return true;
-
- return false;
-}
-
-static bool match_sysattr(sd_device_enumerator *enumerator, sd_device *device) {
- const char *sysattr;
- const char *value;
-
- assert(enumerator);
- assert(device);
-
- HASHMAP_FOREACH_KEY(value, sysattr, enumerator->nomatch_sysattr)
- if (match_sysattr_value(device, sysattr, value))
- return false;
-
- HASHMAP_FOREACH_KEY(value, sysattr, enumerator->match_sysattr)
- if (!match_sysattr_value(device, sysattr, value))
- return false;
-
- return true;
-}
-
static bool match_property(sd_device_enumerator *enumerator, sd_device *device) {
const char *property;
const char *value;
if (!match_property(enumerator, device))
continue;
- if (!match_sysattr(enumerator, device))
+ if (!device_match_sysattr(device, enumerator->match_sysattr, enumerator->nomatch_sysattr))
continue;
k = device_enumerator_add_device(enumerator, device);
if (!match_property(enumerator, device))
continue;
- if (!match_sysattr(enumerator, device))
+ if (!device_match_sysattr(device, enumerator->match_sysattr, enumerator->nomatch_sysattr))
continue;
k = device_enumerator_add_device(enumerator, device);
if (!match_property(enumerator, device))
return 0;
- if (!match_sysattr(enumerator, device))
+ if (!device_match_sysattr(device, enumerator->match_sysattr, enumerator->nomatch_sysattr))
return 0;
r = device_enumerator_add_device(enumerator, device);
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <fnmatch.h>
+
+#include "device-util.h"
+
+static bool device_match_sysattr_value(sd_device *device, const char *sysattr, const char *match_value) {
+ const char *value;
+
+ assert(device);
+ assert(sysattr);
+
+ if (sd_device_get_sysattr_value(device, sysattr, &value) < 0)
+ return false;
+
+ if (!match_value)
+ return true;
+
+ if (fnmatch(match_value, value, 0) == 0)
+ return true;
+
+ return false;
+}
+
+bool device_match_sysattr(sd_device *device, Hashmap *match_sysattr, Hashmap *nomatch_sysattr) {
+ const char *sysattr;
+ const char *value;
+
+ assert(device);
+
+ HASHMAP_FOREACH_KEY(value, sysattr, match_sysattr)
+ if (!device_match_sysattr_value(device, sysattr, value))
+ return false;
+
+ HASHMAP_FOREACH_KEY(value, sysattr, nomatch_sysattr)
+ if (device_match_sysattr_value(device, sysattr, value))
+ return false;
+
+ return true;
+}
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include <stdbool.h>
+
#include "sd-device.h"
+#include "hashmap.h"
+#include "log.h"
+#include "macro.h"
+
#define FOREACH_DEVICE_PROPERTY(device, key, value) \
for (key = sd_device_get_property_first(device, &(value)); \
key; \
#define log_device_notice_errno(device, error, ...) log_device_full_errno(device, LOG_NOTICE, error, __VA_ARGS__)
#define log_device_warning_errno(device, error, ...) log_device_full_errno(device, LOG_WARNING, error, __VA_ARGS__)
#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);