From: Yu Watanabe Date: Fri, 11 Sep 2020 08:41:10 +0000 (+0900) Subject: sd-device: introduce sd_device_set_sysattr_valuef() X-Git-Tag: v247-rc1~256^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea2bc257623833311965a798611f2dc114a569e8;p=thirdparty%2Fsystemd.git sd-device: introduce sd_device_set_sysattr_valuef() --- diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 1bee5318d67..c6dfcd67912 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -732,4 +732,5 @@ global: sd_device_get_current_tag_first; sd_device_get_current_tag_next; sd_device_has_current_tag; + sd_device_set_sysattr_valuef; } LIBSYSTEMD_246; diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index bf92fda6d95..634c9a24f86 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1979,3 +1979,26 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, return 0; } + +_public_ int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) { + _cleanup_free_ char *value = NULL; + va_list ap; + int r; + + assert_return(device, -EINVAL); + assert_return(sysattr, -EINVAL); + + if (!format) { + device_remove_sysattr_value(device, sysattr); + return 0; + } + + va_start(ap, format); + r = vasprintf(&value, format, ap); + va_end(ap); + + if (r < 0) + return -ENOMEM; + + return sd_device_set_sysattr_value(device, sysattr, value); +} diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h index d720ce50da1..53092d28f92 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -79,6 +79,7 @@ int sd_device_get_property_value(sd_device *device, const char *key, const char int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value); int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *value); +int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) _sd_printf_(3, 4); /* device enumerator */