changeset 1596:6eee35009294 draft

Fix bug pointed out by Elliott Hughes ("vmstat 1" should repeat endlessly), and remove final delay (after all output) for "vmstat 2 3" case.
author Rob Landley <rob@landley.net>
date Tue, 02 Dec 2014 16:02:50 -0600
parents 9db327a6920d
children 5de199de14ba
files toys/other/vmstat.c
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/toys/other/vmstat.c	Tue Dec 02 13:00:08 2014 -0600
+++ b/toys/other/vmstat.c	Tue Dec 02 16:02:50 2014 -0600
@@ -84,11 +84,13 @@
   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 @@
     }
     xputc('\n');
 
-    if (loop_delay) sleep(loop_delay);
-    else break;
+    if (!loop_delay) break;
   }
 }