]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysctl: disable buffer while writing to /proc 7618/head
authorTiago Salem Herrmann <therrmann@suse.com>
Tue, 12 Dec 2017 15:52:45 +0000 (13:52 -0200)
committerTiago Salem Herrmann <therrmann@suse.com>
Wed, 13 Dec 2017 17:03:41 +0000 (15:03 -0200)
fputs() writes only first 2048 bytes and fails
to write to /proc when values are larger than that.
This patch adds a new flag to WriteStringFileFlags
that make it possible to disable the buffer under
specific cases.

src/basic/fileio.c
src/basic/fileio.h
src/shared/sysctl-util.c

index 12d6d06fa2964d4dce3398d682da76b11a706137..76c9333d2613113b7d5d64670f898df61473ea9d 100644 (file)
@@ -167,6 +167,9 @@ int write_string_file_ts(
                 }
         }
 
+        if (flags & WRITE_STRING_FILE_DISABLE_BUFFER)
+                setvbuf(f, NULL, _IONBF, 0);
+
         r = write_string_stream_ts(f, line, flags, ts);
         if (r < 0)
                 goto fail;
index c283f41f09ba0768bd44946b50e67cf22e09e605..da5d5c66b51c5c526cd9d899e509545fb6f99d99 100644 (file)
@@ -35,6 +35,7 @@ typedef enum {
         WRITE_STRING_FILE_AVOID_NEWLINE     = 1<<2,
         WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1<<3,
         WRITE_STRING_FILE_SYNC              = 1<<4,
+        WRITE_STRING_FILE_DISABLE_BUFFER    = 1<<5,
 
         /* And before you wonder, why write_string_file_atomic_label_ts() is a separate function instead of just one
            more flag here: it's about linking: we don't want to pull -lselinux into all users of write_string_file()
index 391065d804a54fdee2d20e83a8f05b097ff6db3e..189580e3ed29d900a591fbf6912ed56c9c26553a 100644 (file)
@@ -60,7 +60,7 @@ int sysctl_write(const char *property, const char *value) {
         log_debug("Setting '%s' to '%s'", property, value);
 
         p = strjoina("/proc/sys/", property);
-        return write_string_file(p, value, 0);
+        return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER);
 }
 
 int sysctl_read(const char *property, char **content) {