Commit fdb347f7 authored by Phil Sutter's avatar Phil Sutter Committed by Stephen Hemminger

lnstat: fix header displaying mechanism

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: e7e2913f ("lnstat: run indefinitely by default")
Signed-off-by: default avatarPhil Sutter <phil@nwl.cc>
parent 869fcabe
...@@ -359,21 +359,19 @@ int main(int argc, char **argv) ...@@ -359,21 +359,19 @@ int main(int argc, char **argv)
if (interval < 1 ) if (interval < 1 )
interval = 1; interval = 1;
for (i = 0; i < count || !count; ) { for (i = 0; i < count || !count; i++) {
lnstat_update(lnstat_files); lnstat_update(lnstat_files);
if (mode == MODE_JSON) if (mode == MODE_JSON)
print_json(stdout, lnstat_files, &fp); print_json(stdout, lnstat_files, &fp);
else { else {
if ((hdr > 1 && if ((hdr > 1 && !(i % 20)) ||
(! (i % 20))) || (hdr == 1 && i == 0)) (hdr == 1 && i == 0))
print_hdr(stdout, header); print_hdr(stdout, header);
print_line(stdout, lnstat_files, &fp); print_line(stdout, lnstat_files, &fp);
} }
fflush(stdout); fflush(stdout);
if (i < count - 1 || !count) if (i < count - 1 || !count)
sleep(interval); sleep(interval);
if (count)
++i;
} }
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment