diff options
author | Tom Gundersen <teg@jklm.no> | 2014-11-11 22:49:41 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-12-11 13:54:18 +0100 |
commit | ded863d8cf5fa0502456c8a7c7cb4ff40c498f12 (patch) | |
tree | 61af3a9855a72148283d1153637af80f5b5487b3 | |
parent | 0f4cd481eb99242da4efec4593222a0f918a7873 (diff) |
sd-device: add sd_device_get_property_value
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 25 | ||||
-rw-r--r-- | src/systemd/sd-device.h | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 88df35d9c..8df59ae30 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1152,3 +1152,28 @@ _public_ int sd_device_get_is_initialized(sd_device *device, int *initialized) { return 0; } + +_public_ int sd_device_get_property_value(sd_device *device, const char *key, const char **_value) { + char *value; + int r; + + assert_return(device, -EINVAL); + assert_return(key, -EINVAL); + assert_return(_value, -EINVAL); + + r = device_read_uevent_file(device); + if (r < 0) + return r; + + r = device_read_db(device); + if (r < 0) + return r; + + value = hashmap_get(device->properties, key); + if (!value) + return -ENOENT; + + *_value = value; + + return 0; +} diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h index 9a74bf0fb..cb910ea93 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -49,6 +49,7 @@ int sd_device_get_devnum(sd_device *device, dev_t *devnum); int sd_device_get_driver(sd_device *device, const char **ret); int sd_device_get_is_initialized(sd_device *device, int *initialized); +int sd_device_get_property_value(sd_device *device, const char *key, const char **value); _SD_END_DECLARATIONS; |