Set *match_sysname;
Set *match_tag;
sd_device *match_parent;
- bool match_is_initialized;
+ bool match_allow_uninitialized;
};
_public_ int sd_device_enumerator_new(sd_device_enumerator **ret) {
assert_return(enumerator, -EINVAL);
assert_return(_sysattr, -EINVAL);
- assert_return(_value, -EINVAL);
if (match)
hashmap = &enumerator->match_sysattr;
if (!sysattr)
return -ENOMEM;
- value = strdup(_value);
- if (!value)
- return -ENOMEM;
+ if (_value) {
+ value = strdup(_value);
+ if (!value)
+ return -ENOMEM;
+ }
r = hashmap_put(*hashmap, sysattr, value);
if (r < 0)
assert_return(enumerator, -EINVAL);
assert_return(_property, -EINVAL);
- assert_return(_value, -EINVAL);
r = hashmap_ensure_allocated(&enumerator->match_property, NULL);
if (r < 0)
if (!property)
return -ENOMEM;
- value = strdup(_value);
- if (!value)
- return -ENOMEM;
+ if (_value) {
+ value = strdup(_value);
+ if (!value)
+ return -ENOMEM;
+ }
r = hashmap_put(enumerator->match_property, property, value);
if (r < 0)
return 0;
}
-_public_ int sd_device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator) {
+_public_ int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator) {
+ assert_return(enumerator, -EINVAL);
+
+ enumerator->match_allow_uninitialized = true;
+
+ enumerator->scan_uptodate = false;
+
+ return 0;
+}
+
+int device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator) {
assert_return(enumerator, -EINVAL);
- enumerator->match_is_initialized = true;
+ enumerator->match_allow_uninitialized = false;
enumerator->scan_uptodate = false;
return strcmp(devpath_a, devpath_b);
}
-_public_ int sd_device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device) {
+int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device) {
int r;
assert_return(enumerator, -EINVAL);
assert(enumerator);
assert(device);
- HASHMAP_FOREACH_KEY(sysattr, value, enumerator->nomatch_sysattr, i)
+ HASHMAP_FOREACH_KEY(value, sysattr, enumerator->nomatch_sysattr, i)
if (match_sysattr_value(device, sysattr, value))
return false;
- HASHMAP_FOREACH_KEY(sysattr, value, enumerator->match_sysattr, i)
+ HASHMAP_FOREACH_KEY(value, sysattr, enumerator->match_sysattr, i)
if (!match_sysattr_value(device, sysattr, value))
return false;
if (hashmap_isempty(enumerator->match_property))
return true;
- HASHMAP_FOREACH_KEY(property, value, enumerator->match_property, i) {
+ HASHMAP_FOREACH_KEY(value, property, enumerator->match_property, i) {
const char *property_dev, *value_dev;
FOREACH_DEVICE_PROPERTY(device, property_dev, value_dev) {
k = sd_device_new_from_syspath(&device, syspath);
if (k < 0) {
- log_debug_errno(k, "device-enumerator: failed to create device from syspath %s: %m", syspath);
- r = k;
+ if (k != -ENODEV)
+ /* this is necessarily racey, so ignore missing devices */
+ r = k;
+
continue;
}
* might not store a database, and have no way to find out
* for all other types of devices.
*/
- if (enumerator->match_is_initialized &&
+ if (!enumerator->match_allow_uninitialized &&
!initialized &&
(major(devnum) > 0 || ifindex > 0))
continue;
if (!match_sysattr(enumerator, device))
continue;
- k = sd_device_enumerator_add_device(enumerator, device);
+ k = device_enumerator_add_device(enumerator, device);
if (k < 0)
r = k;
}
k = sd_device_new_from_device_id(&device, dent->d_name);
if (k < 0) {
- r = k;
+ if (k != -ENODEV)
+ /* this is necessarily racy, so ignore missing devices */
+ r = k;
+
continue;
}
if (!match_sysattr(enumerator, device))
continue;
- k = sd_device_enumerator_add_device(enumerator, device);
+ k = device_enumerator_add_device(enumerator, device);
if (k < 0) {
r = k;
continue;
int r;
r = sd_device_new_from_syspath(&device, path);
- if (r == -ENOENT)
+ if (r == -ENODEV)
+ /* this is necessarily racy, so ignore missing devices */
return 0;
else if (r < 0)
return r;
if (!match_sysattr(enumerator, device))
return 0;
- r = sd_device_enumerator_add_device(enumerator, device);
+ r = device_enumerator_add_device(enumerator, device);
if (r < 0)
return r;
if (dent->d_type != DT_DIR)
continue;
- k = asprintf(&child, "%s/%s", path, dent->d_name);
- if (k < 0)
- return -errno;
+ child = strjoin(path, "/", dent->d_name, NULL);
+ if (!child)
+ return -ENOMEM;
k = parent_add_child(enumerator, child);
if (k < 0)