mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
udev-util: add wrapper for sd_device_get_property_value()
... that allows to pass additional properties to fall back to.
This commit is contained in:
@@ -410,3 +410,30 @@ int device_get_model_string(sd_device *device, const char **ret) {
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
int device_get_property_value_with_fallback(
|
||||
sd_device *device,
|
||||
const char *prop,
|
||||
Hashmap *extra_props,
|
||||
const char **ret) {
|
||||
const char *value;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
assert(prop);
|
||||
assert(ret);
|
||||
|
||||
r = sd_device_get_property_value(device, prop, &value);
|
||||
if (r < 0) {
|
||||
if (r != -ENOENT)
|
||||
return r;
|
||||
|
||||
value = hashmap_get(extra_props, prop);
|
||||
if (!value)
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
*ret = value;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "time-util.h"
|
||||
|
||||
int udev_set_max_log_level(char *str);
|
||||
@@ -25,3 +26,9 @@ bool udev_available(void);
|
||||
|
||||
int device_get_vendor_string(sd_device *device, const char **ret);
|
||||
int device_get_model_string(sd_device *device, const char **ret);
|
||||
|
||||
int device_get_property_value_with_fallback(
|
||||
sd_device *device,
|
||||
const char *prop,
|
||||
Hashmap *extra_props,
|
||||
const char **ret);
|
||||
|
||||
Reference in New Issue
Block a user