]> arthur.barton.de Git - netdata.git/blobdiff - src/procfile.c
fixed minor issues throughout the code (mainly types); dashboard has now a watermark...
[netdata.git] / src / procfile.c
index f2269457d0d657c0a4096220b272c0672ebfd9b3..7a48579593caceb6fdfccbab710f359acc5d1142 100755 (executable)
@@ -1,3 +1,6 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -5,7 +8,6 @@
 #include <fcntl.h>
 #include <string.h>
 #include <malloc.h>
-#include <inttypes.h>
 #include <ctype.h>
 #include <time.h>
 #include <sys/time.h>
@@ -157,7 +159,7 @@ procfile *procfile_parser(procfile *ff) {
        char *s = ff->data, *e = ff->data, *t = ff->data;
        uint32_t l = 0, w = 0;
        e += ff->len;
-       
+
        ff->lines = pflines_add(ff->lines, w);
        if(unlikely(!ff->lines)) goto cleanup;
 
@@ -233,11 +235,14 @@ cleanup:
 procfile *procfile_readall(procfile *ff) {
        debug(D_PROCFILE, PF_PREFIX ": Reading file '%s'.", ff->filename);
 
-       ssize_t s = 0, r = ff->size, x = ff->size;
+       ssize_t s, r = 1, x;
        ff->len = 0;
 
-       while(likely(r == x)) {
-               if(s) {
+       while(likely(r > 0)) {
+               s = ff->len;
+               x = ff->size - s;
+
+               if(!x) {
                        debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s'.", ff->filename);
 
                        procfile *new = realloc(ff, sizeof(procfile) + ff->size + PROCFILE_INCREMENT_BUFFER);
@@ -248,7 +253,6 @@ procfile *procfile_readall(procfile *ff) {
                        }
                        ff = new;
                        ff->size += PROCFILE_INCREMENT_BUFFER;
-                       x = PROCFILE_INCREMENT_BUFFER;
                }
 
                debug(D_PROCFILE, "Reading file '%s', from position %ld with length %ld", ff->filename, s, ff->size - s);
@@ -260,7 +264,6 @@ procfile *procfile_readall(procfile *ff) {
                }
 
                ff->len += r;
-               s = ff->len;
        }
 
        debug(D_PROCFILE, "Rewinding file '%s'", ff->filename);