[Toybox] vmstat bug + patch

enh enh at google.com
Sun May 10 11:09:54 PDT 2015


+2. i reproduced the bug, and this patch fixes it.

On Sat, May 9, 2015 at 10:47 PM, Graham Watt <gmwatt at gmail.com> wrote:

> There's a bug in vmstat that causes junk to be printed instead of the
> headers when repeating. This can be duplicated by running `vmstat 1`
> and waiting for the headers to be printed again.
> Here is a patch for the issue.
>
>
> diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
> index eed7945..2685c11 100644
> --- a/toys/other/vmstat.c
> +++ b/toys/other/vmstat.c
> @@ -77,8 +77,9 @@ void vmstat_main(void)
>    int i, loop_delay = 0, loop_max = 0;
>    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"
> -                "sy\0id\0wa", lengths[] =
> {2,2,6,6,6,6,4,4,5,5,4,4,2,2,2,2};
> +  char
> *headers[]={"r","b","swpd","free","buff","cache","si","so","bi","bo",
> +                  "in","cs","us","sy","id","wa"},
> +       lengths[] = {2,2,6,6,6,6,4,4,5,5,4,4,2,2,2,2};
>
>    memset(top, 0, sizeof(top));
>    if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX);
> @@ -99,8 +100,7 @@ void vmstat_main(void)
>        printf("procs -----------memory---------- ---swap-- -----io----
> -system-- ----cpu----\n");
>
>        for (i=0; i<sizeof(lengths); i++) {
> -        printf(" %*s"+!i, lengths[i], headers);
> -        headers += strlen(headers)+1;
> +        printf(" %*s"+!i, lengths[i], headers[i]);
>        }
>        xputc('\n');
>      }
>
> --
> Graham Watt
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150510/85b0cddb/attachment-0002.htm>


More information about the Toybox mailing list