]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysctl: add sysctl_writef() helper
authorLennart Poettering <lennart@poettering.net>
Fri, 12 Jul 2019 08:34:04 +0000 (10:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 13 Jul 2019 09:05:07 +0000 (11:05 +0200)
src/shared/sysctl-util.c
src/shared/sysctl-util.h

index 9be4055b37696f6677973f5b701ed87bea167931..93bdcf11bf4effa16e7e5effc28f99d27a8c7675 100644 (file)
@@ -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;
 
index d50c6e438162119af38607745c4fe88ebe2554dd..cb30a9775240a5200a34371181f6045ce2aa8691 100644 (file)
@@ -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);