]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lnstat: fix header displaying mechanism
authorPhil Sutter <phil@nwl.cc>
Wed, 18 Nov 2015 15:57:47 +0000 (16:57 +0100)
committerStephen Hemminger <shemming@brocade.com>
Mon, 23 Nov 2015 23:54:05 +0000 (15:54 -0800)
The algorithm depends on the loop counter ('i') to increment by one in
each iteration. Though if running endlessly (count==0), the counter was
not incremented at all.

Also change formatting of the header printing conditional a bit so it's
hopefully easier to read.

Fixes: e7e2913 ("lnstat: run indefinitely by default")
Signed-off-by: Phil Sutter <phil@nwl.cc>
misc/lnstat.c

index 529bc33d852f3411ead792b4754c4035f61f198c..264c9531a561fb94ce502033b69cdd00a423ea86 100644 (file)
@@ -359,21 +359,19 @@ int main(int argc, char **argv)
                if (interval < 1 )
                        interval = 1;
 
-               for (i = 0; i < count || !count; ) {
+               for (i = 0; i < count || !count; i++) {
                        lnstat_update(lnstat_files);
                        if (mode == MODE_JSON)
                                print_json(stdout, lnstat_files, &fp);
                        else {
-                               if  ((hdr > 1 &&
-                                     (! (i % 20))) || (hdr == 1 && i == 0))
+                               if  ((hdr > 1 && !(i % 20)) ||
+                                    (hdr == 1 && i == 0))
                                        print_hdr(stdout, header);
                                print_line(stdout, lnstat_files, &fp);
                        }
                        fflush(stdout);
                        if (i < count - 1 || !count)
                                sleep(interval);
-                       if (count)
-                               ++i;
                }
                break;
        }