diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-07-12 10:34:04 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-07-13 11:05:07 +0200 |
commit | 6a47f2a7149ec86eb682cc178b3ea7fcf3151564 (patch) | |
tree | f51082c307d84a1e1e17ddbfebdb54a1e56b8425 | |
parent | shutdown: use "int" for log level type (diff) | |
download | systemd-6a47f2a7149ec86eb682cc178b3ea7fcf3151564.tar.xz systemd-6a47f2a7149ec86eb682cc178b3ea7fcf3151564.zip |
sysctl: add sysctl_writef() helper
-rw-r--r-- | src/shared/sysctl-util.c | 15 | ||||
-rw-r--r-- | src/shared/sysctl-util.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/shared/sysctl-util.c b/src/shared/sysctl-util.c index 9be4055b37..93bdcf11bf 100644 --- a/src/shared/sysctl-util.c +++ b/src/shared/sysctl-util.c @@ -60,6 +60,21 @@ int sysctl_write(const char *property, const char *value) { return 0; } +int sysctl_writef(const char *property, const char *format, ...) { + _cleanup_free_ char *v = NULL; + va_list ap; + int r; + + va_start(ap, format); + r = vasprintf(&v, format, ap); + va_end(ap); + + if (r < 0) + return -ENOMEM; + + return sysctl_write(property, v); +} + int sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value) { const char *p; diff --git a/src/shared/sysctl-util.h b/src/shared/sysctl-util.h index d50c6e4381..cb30a97752 100644 --- a/src/shared/sysctl-util.h +++ b/src/shared/sysctl-util.h @@ -11,6 +11,7 @@ char *sysctl_normalize(char *s); int sysctl_read(const char *property, char **value); int sysctl_write(const char *property, const char *value); +int sysctl_writef(const char *propery, const char *format, ...) _printf_(2, 3); int sysctl_read_ip_property(int af, const char *ifname, const char *property, char **ret); int sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value); |