[Toybox] [PATCH] fix "vmstat 2"

enh enh at google.com
Tue Nov 25 19:14:15 PST 2014


actually, loop_max =1 gives the right behavior by accident (because of
the break in the loop), so setting loop_max = 0 is a better idea.

diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
index 49c7cc7..6b5cbd2 100644
--- a/toys/other/vmstat.c
+++ b/toys/other/vmstat.c
@@ -74,7 +74,7 @@ error:
 void vmstat_main(void)
 {
   struct vmstat_proc top[2];
-  int i, loop_delay = 0, loop_max = 0;
+  int i, loop_delay = 0, loop_max = INT_MAX;
   unsigned loop, rows = (toys.optflags & FLAG_n) ? 0 : 25,
            page_kb = sysconf(_SC_PAGESIZE)/1024;
   char *headers="r\0b\0swpd\0free\0buff\0cache\0si\0so\0bi\0bo\0in\0cs\0us\0"
@@ -82,6 +82,7 @@ void vmstat_main(void)

   memset(top, 0, sizeof(top));
   if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX);
+  else loop_max = 0;
   if (toys.optc > 1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX) - 1;

   for (loop = 0; loop <= loop_max; loop++) {


On Tue, Nov 25, 2014 at 5:24 PM, enh <enh at google.com> wrote:
> The documentation was already correct: "(With no DELAY, prints one
> line. With no COUNT, repeats until killed.)".
>
> diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
> index 49c7cc7..510b3b6 100644
> --- a/toys/other/vmstat.c
> +++ b/toys/other/vmstat.c
> @@ -74,7 +74,7 @@ error:
>  void vmstat_main(void)
>  {
>    struct vmstat_proc top[2];
> -  int i, loop_delay = 0, loop_max = 0;
> +  int i, loop_delay = 0, loop_max = INT_MAX;
>    unsigned loop, rows = (toys.optflags & FLAG_n) ? 0 : 25,
>             page_kb = sysconf(_SC_PAGESIZE)/1024;
>    char *headers="r\0b\0swpd\0free\0buff\0cache\0si\0so\0bi\0bo\0in\0cs\0us\0"
> @@ -82,6 +82,7 @@ void vmstat_main(void)
>
>    memset(top, 0, sizeof(top));
>    if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX);
> +  else loop_max = 1;
>    if (toys.optc > 1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX) - 1;
>
>    for (loop = 0; loop <= loop_max; loop++) {

 1416971655.0


More information about the Toybox mailing list