else
hashmap = &enumerator->nomatch_sysattr;
- r = update_match_strv(hashmap, sysattr, value);
+ r = update_match_strv(hashmap, sysattr, value, /* clear_on_null = */ true);
if (r <= 0)
return r;
assert_return(enumerator, -EINVAL);
assert_return(property, -EINVAL);
- /* Do not use string_has_ops_free_free or hashmap_put_strdup() here, as this may be called
- * multiple times with the same property but different value. */
- r = hashmap_put_strdup_full(&enumerator->match_property, &trivial_hash_ops_free_free, property, value);
+ r = update_match_strv(&enumerator->match_property, property, value, /* clear_on_null = */ false);
if (r <= 0)
return r;
}
static bool match_property(sd_device_enumerator *enumerator, sd_device *device) {
- const char *property;
- const char *value;
+ const char *property_pattern;
+ char * const *value_patterns;
assert(enumerator);
assert(device);
+ /* Unlike device_match_sysattr(), this accepts device that has at least one matching property. */
+
if (hashmap_isempty(enumerator->match_property))
return true;
- HASHMAP_FOREACH_KEY(value, property, enumerator->match_property) {
- const char *property_dev, *value_dev;
-
- FOREACH_DEVICE_PROPERTY(device, property_dev, value_dev) {
- if (fnmatch(property, property_dev, 0) != 0)
- continue;
-
- if (!value && !value_dev)
- return true;
+ HASHMAP_FOREACH_KEY(value_patterns, property_pattern, enumerator->match_property) {
+ const char *property, *value;
- if (!value || !value_dev)
+ FOREACH_DEVICE_PROPERTY(device, property, value) {
+ if (fnmatch(property_pattern, property, 0) != 0)
continue;
- if (fnmatch(value, value_dev, 0) == 0)
+ if (strv_fnmatch(value_patterns, value))
return true;
}
}
hashmap = &m->nomatch_sysattr_filter;
/* TODO: unset m->filter_uptodate on success when we support this filter on BPF. */
- return update_match_strv(hashmap, sysattr, value);
+ return update_match_strv(hashmap, sysattr, value, /* clear_on_null = */ true);
}
_public_ int sd_device_monitor_filter_add_match_parent(sd_device_monitor *m, sd_device *device, int match) {
#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__)
-int update_match_strv(Hashmap **match_strv, const char *key, const char *value);
+int update_match_strv(Hashmap **match_strv, const char *key, const char *value, bool clear_on_null);
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);