library: some tweaks to 2 file read functions, 3rd gen

Ever since their introduction, plus continuing through
several evolutions, both the meminfo and vmstat 'read'
functions employed a 'do while' loop for /proc access.

However, that loop construct was wrong since identical
tests were already done (twice!) within each loop body
itself, then accompanied by its own 'break' statement.

So, we will now transform them both into forever loops
which will help us to emphasize such break statements.

[ plus, let's return an error should nothing be read ]

[ lastly, eliminate 1 erroneous PROCPS_EXPORT prefix ]

Reference(s):
. original meminfo introduction
commit a20e88e4e7
. original vmstat introduction
commit a410e236ab

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-07-03 00:00:00 -05:00 committed by Craig Small
parent 62abd1d88b
commit a6115bfff4
2 changed files with 8 additions and 9 deletions

View File

@ -534,7 +534,7 @@ static int make_hash_failed (
* Read the data out of /proc/meminfo putting the information
* into the supplied info structure
*/
PROCPS_EXPORT int read_meminfo_failed (
static int read_meminfo_failed (
struct procps_meminfo *info)
{
/* a 'memory history reference' macro for readability,
@ -570,11 +570,11 @@ PROCPS_EXPORT int read_meminfo_failed (
break;
}
if (size == 0)
return 0;
return -1;
buf[size] = '\0';
head = buf;
do {
for (;;) {
static ENTRY e; // just to keep coverity off our backs (e.data)
ENTRY *ep;
@ -589,16 +589,15 @@ PROCPS_EXPORT int read_meminfo_failed (
valptr = ep->data;
head = tail+1;
if (valptr) {
if (valptr)
*valptr = strtoul(head, &tail, 10);
}
tail = strchr(head, '\n');
if (!tail)
break;
head = tail + 1;
} while(tail);
}
if (0 == mHr(MemAvailable))
mHr(MemAvailable) = mHr(MemFree);

View File

@ -995,11 +995,11 @@ static int read_vmstat_failed (
break;
}
if (size == 0)
return 0;
return -1;
buf[size] = '\0';
head = buf;
do {
for (;;) {
static ENTRY e; // just to keep coverity off our backs (e.data)
ENTRY *ep;
@ -1022,7 +1022,7 @@ static int read_vmstat_failed (
break;
head = tail + 1;
} while(tail);
}
// let's not distort the deltas the first time thru ...
if (!info->vmstat_was_read)