Page MenuHomeFreeBSD

netstat(1): '-w': Banners to appear before a new statistics line, not after
Needs ReviewPublic

Authored by olce on Thu, Apr 2, 7:49 PM.

Details

Reviewers
glebius
Summary

Recurring banners except the first are printed just after the latest
interval's statistics line, giving the false impression that the latter
are omitted. It is also better to print a new banner only if it is
going to be followed by a new line of statistics, in case netstat(1) is
interrupted or we have reached the number of iterations specified by
'-q'.

Fix this by pushing printing these banners inside the loop producing
statistics lines, after having waited for the next interval.

The first banner is printed before the loop, as we want it to be printed
immediately at launch, even if at this point we do not have statistics
to display (we have to wait for an interval to compute these, as they
are based on a difference).

While here, remove the 'goto' spaghetti by putting banner printing into
its own private function and using a proper infinite loop in
sidewaysintpr().

While here, document the why of the 21 statistics line span between two
banners.

While here, check for the number of output lines of statistics once such
a line has effectively been printed. This allows to remove the internal
incrementation performed when reading '-w''s argument, which was a hack
to compensate the misplaced check.

While here, in the manual page, simplify the description of the '-w'
mode and mention that passing 0 to '-q' means "no count limit".

Fixes: 84c1edcbad7d ("Rewrite netstat/if.c to use ...")
Fixes: bf10ffe1d3a9 ("Add a new option, -q howmany, ...")
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 71941
Build 68824: arc lint + arc unit

Event Timeline

olce requested review of this revision.Thu, Apr 2, 7:49 PM
glebius requested changes to this revision.Thu, Apr 2, 9:34 PM

Thanks a lot for noticing the problem. I didn't test, but it looks to me that the fix will regress the very first line of the output. It is now printed immediately and will consist of zeroes or very small values.

This revision now requires changes to proceed.Thu, Apr 2, 9:34 PM
olce retitled this revision from netstat(1): On '-w', print statistics also on banner printing to netstat(1): '-w': Print statistics along with banners, '-q' not to count banners.
olce edited the summary of this revision. (Show Details)

Wait one interval to print the first statistics line.

For more details, see the updated commit message.

This revision is now accepted and ready to land.Fri, Apr 3, 3:33 PM
olce retitled this revision from netstat(1): '-w': Print statistics along with banners, '-q' not to count banners to netstat(1): '-w': Banners to appear before a new statistics line, not after.
olce edited the summary of this revision. (Show Details)
  • Restore the check on 21 statistics line, which was tailored for 24-line displays, and update the corresponding comment.
  • Fix the commit message. After an additional check, no statistics line is actually missing. The fact that a new banner is printed *after* the statistics of the latest interval was really confusing and should be fixed. Additionally, we want to avoid a trailing banner in case of interruption or the requested number of statistics line has been reached.
This revision now requires review to proceed.Fri, Apr 3, 3:34 PM