[procps] [PATCH 1/2] Increase standard I/O buffer a lot to be able to

  • From: Werner Fink <werner@xxxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Fri, 7 Jul 2017 14:09:11 +0200

read huge informations at once as otherwise all files below
/proc/sys, not using the seq_file API at the kernel side,
will return EOF on a second read.

Signed-off-by: Werner Fink <werner@xxxxxxx>
---
 sysctl.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git sysctl.c sysctl.c
index 29f31af..be05722 100644
--- sysctl.c
+++ sysctl.c
@@ -158,6 +158,8 @@ static char *StripLeadingAndTrailingSpaces(char *oneline)
 /*
  * Read a sysctl setting
  */
+#define IOBUFSIZ    (128<<10)
+static char *iobuf;
 static int ReadSetting(const char *restrict const name)
 {
        int rc = 0;
@@ -220,6 +222,9 @@ static int ReadSetting(const char *restrict const name)
 
        fp = fopen(tmpname, "r");
 
+       if (iobuf)
+               setvbuf(fp, iobuf, _IOFBF, IOBUFSIZ);
+
        if (!fp) {
                switch (errno) {
                case ENOENT:
@@ -430,6 +435,9 @@ static int WriteSetting(const char *setting)
 
        fp = fopen(tmpname, "w");
 
+       if (iobuf)
+               setvbuf(fp, iobuf, _IOFBF, IOBUFSIZ);
+
        if (!fp) {
                switch (errno) {
                case ENOENT:
@@ -793,6 +801,8 @@ int main(int argc, char *argv[])
        argc -= optind;
        argv += optind;
 
+       iobuf = (char*)malloc(IOBUFSIZ);        /* Allow to fail */
+
        if (DisplayAllOpt)
                return DisplayAll(PROC_PATH);
 
-- 
2.12.3


Other related posts:

  • » [procps] [PATCH 1/2] Increase standard I/O buffer a lot to be able to - Werner Fink