aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-03-16 11:33:42 -0700
committerRob Landley <rob@landley.net>2018-03-21 10:00:56 -0500
commit133915d49405693b587c3e67fc56c186543ae210 (patch)
tree42e36d4b38b55f4a76d53e651538ba6bc168b450 /toys
parent07fc8fc5273070fa4ac99d456c484f96c2ae7341 (diff)
downloadtoybox-133915d49405693b587c3e67fc56c186543ae210.tar.gz
Fix vmstat for large machines.
48 cores is too much to fit in toybuf.
Diffstat (limited to 'toys')
-rw-r--r--toys/other/vmstat.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
index ae856cf6..a16afe65 100644
--- a/toys/other/vmstat.c
+++ b/toys/other/vmstat.c
@@ -48,7 +48,7 @@ static void get_vmstat_proc(struct vmstat_proc *vmstat_proc)
"MemFree: ", "Buffers: ", "Cached: ", "SwapFree: ", "SwapTotal: ",
"/proc/vmstat", "pgpgin ", "pgpgout ", "pswpin ", "pswpout " };
uint64_t *new = (uint64_t *)vmstat_proc;
- char *p = p, *name = name;
+ char *p = p, *name = name, *file = NULL;
int i, j;
// We use vmstuff to fill out vmstat_proc as an array of uint64_t:
@@ -56,21 +56,23 @@ static void get_vmstat_proc(struct vmstat_proc *vmstat_proc)
// Any other string is a key to search for, with decimal value right after
// 0 means parse another value on same line as last key
- for (i = 0; i<sizeof(vmstuff)/sizeof(char *); i++) {
+ for (i = 0; i<ARRAY_LEN(vmstuff); i++) {
if (!vmstuff[i]) p++;
else if (*vmstuff[i] == '/') {
- xreadfile(name = vmstuff[i], toybuf, sizeof(toybuf));
+ // /proc/stat for a 48-core machine doesn't fit in toybuf.
+ free(file);
+ file = xreadfile(name = vmstuff[i], 0, 0);
continue;
- } else if (!(p = strafter(toybuf, vmstuff[i]))) goto error;
- if (1 != sscanf(p, "%"PRIu64"%n", new++, &j)) goto error;
+ } else if (!(p = strafter(file, vmstuff[i]))) {
+ error_exit("No %sin %s", vmstuff[i], name);
+ }
+ if (1 != sscanf(p, "%"PRIu64"%n", new++, &j)) {
+ error_exit("Bad %sin %s: %s", vmstuff[i], name, p);
+ }
p += j;
}
-
- return;
-
-error:
- error_exit("No %sin %s\n", vmstuff[i], name);
+ free(file);
}
void vmstat_main(void)