udev/builtin: introduce udev_builtin_import_property() helper function

This is not used in this commit, but will be used later commits.
This commit is contained in:
Yu Watanabe 2024-01-09 01:12:20 +09:00
parent 12b1e04073
commit 50a0379d5d
2 changed files with 24 additions and 0 deletions

View file

@ -154,3 +154,26 @@ int udev_builtin_add_propertyf(sd_device *dev, bool test, const char *key, const
return udev_builtin_add_property(dev, test, key, val);
}
int udev_builtin_import_property(sd_device *dev, sd_device *src, bool test, const char *key) {
const char *val;
int r;
assert(dev);
assert(key);
if (!src)
return 0;
r = sd_device_get_property_value(src, key, &val);
if (r == -ENOENT)
return 0;
if (r < 0)
return log_device_debug_errno(src, r, "Failed to get property \"%s\", ignoring: %m", key);
r = udev_builtin_add_property(dev, test, key, val);
if (r < 0)
return r;
return 1;
}

View file

@ -84,5 +84,6 @@ void udev_builtin_list(void);
bool udev_builtin_should_reload(void);
int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val);
int udev_builtin_add_propertyf(sd_device *dev, bool test, const char *key, const char *valf, ...) _printf_(4, 5);
int udev_builtin_import_property(sd_device *dev, sd_device *src, bool test, const char *key);
int udev_builtin_hwdb_lookup(sd_device *dev, const char *prefix, const char *modalias,
const char *filter, bool test);