]> git.ipfire.org Git - thirdparty/iproute2.git/commit
ifstat, nstat: fix daemon mode
authorPhil Sutter <phil@nwl.cc>
Wed, 2 Mar 2016 15:56:27 +0000 (16:56 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Sun, 6 Mar 2016 20:49:05 +0000 (12:49 -0800)
commitdd81ee04edc3461653f1254084e2294083ccdca6
treec997160c4da98817d0b60bf678b72f86611c0554
parent5f4d27d533917ccce4249c1d367aabf606167c47
ifstat, nstat: fix daemon mode

Since the relevant code (and it's bugs) is identical in both files, fix
them in one go. This patch fixes multiple issues:

* Using 'int' for the 'tdiff' variable does not suffice on 64bit
  systems, the assigned initial time difference makes it wrap and
  contain a negative value afterwards. Instead use the more appropriate
  'time_t' type.

* As far as I understood the code, poll() is supposed to time out just
  at the right time to trigger update_db() in the configured interval.
  Therefore it's timeout must be set to the desired interval *minus* the
  time that has already passed since then.

* With the last change to the algorithm in place, it does not make sense
  to call update_db() before returning data to the connected client.
  Actually, it never does otherwise we could skip the periodic updates
  in the first place.

Signed-off-by: Phil Sutter <phil@nwl.cc>
misc/ifstat.c
misc/nstat.c