aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-12-02 16:02:50 -0600
committerRob Landley <rob@landley.net>2014-12-02 16:02:50 -0600
commitfad2fb09b840ebfeb3612800eec0fdb4b7d8a795 (patch)
treec976579b5c0ef01d135238abf9b1894f81eb30fa /toys
parentbce8a514aaf0a7e8b98ff20217c7a44a50aa46de (diff)
downloadtoybox-fad2fb09b840ebfeb3612800eec0fdb4b7d8a795.tar.gz
Fix bug pointed out by Elliott Hughes ("vmstat 1" should repeat endlessly), and remove final delay (after all output) for "vmstat 2 3" case.
Diffstat (limited to 'toys')
-rw-r--r--toys/other/vmstat.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
index 49c7cc72..eed79459 100644
--- a/toys/other/vmstat.c
+++ b/toys/other/vmstat.c
@@ -84,11 +84,13 @@ void vmstat_main(void)
if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX);
if (toys.optc > 1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX) - 1;
- for (loop = 0; loop <= loop_max; loop++) {
+ for (loop = 0; !loop_max || loop <= loop_max; loop++) {
unsigned idx = loop&1, offset = 0, expected = 0;
uint64_t units, total_hz, *ptr = (uint64_t *)(top+idx),
*oldptr = (uint64_t *)(top+!idx);
+ if (loop && loop_delay) sleep(loop_delay);
+
// Print headers
if (rows>3 && !(loop % (rows-3))) {
if (isatty(1)) terminal_size(0, &rows);
@@ -147,7 +149,6 @@ void vmstat_main(void)
}
xputc('\n');
- if (loop_delay) sleep(loop_delay);
- else break;
+ if (!loop_delay) break;
}
}