diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-07-15 09:08:10 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-07-23 08:11:36 +0900 |
commit | 2829fca249bd58a8cd52013d625701e2b8e31737 (patch) | |
tree | 4b78d02a23fa8edd133b20fba2d9a8df6ca19f62 | |
parent | b05e52000b4eee764b383cc3031da0a3739e996e (diff) | |
download | systemd-2829fca249bd58a8cd52013d625701e2b8e31737.tar.gz |
sd-device: introduce device_get_sysattr_bool()
-rw-r--r-- | src/libsystemd/sd-device/device-private.h | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h index 9602f9eda3..93c1d20a01 100644 --- a/src/libsystemd/sd-device/device-private.h +++ b/src/libsystemd/sd-device/device-private.h @@ -18,6 +18,7 @@ static inline int device_new_from_watch_handle(sd_device **ret, int wd) { } int device_get_property_bool(sd_device *device, const char *key); +int device_get_sysattr_bool(sd_device *device, const char *sysattr); int device_get_device_id(sd_device *device, const char **ret); int device_get_devlink_priority(sd_device *device, int *ret); int device_get_watch_handle(sd_device *device); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index a53f31e5ff..6c034626e7 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -2166,6 +2166,20 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, return 0; } +int device_get_sysattr_bool(sd_device *device, const char *sysattr) { + const char *value; + int r; + + assert(device); + assert(sysattr); + + r = sd_device_get_sysattr_value(device, sysattr, &value); + if (r < 0) + return r; + + return parse_boolean(value); +} + static void device_remove_cached_sysattr_value(sd_device *device, const char *_key) { _cleanup_free_ char *key = NULL; |