Commit Graph

24 Commits

Author SHA1 Message Date
Serhey Popovych
5433656705 ip: Use single variable to represent -pretty
After commit a233caa0aa ("json: make pretty printing optional") I get
following build failure:

    LINK     rtmon
    ../lib/libutil.a(json_print.o): In function `new_json_obj':
    json_print.c:(.text+0x35): undefined reference to `show_pretty'
    collect2: error: ld returned 1 exit status
    make[1]: *** [rtmon] Error 1
    make: *** [all] Error 2

It is caused by missing show_pretty variable in rtmon.

On the other hand tc/tc.c there are two distinct variables and single
matches() call that handles -pretty option thus setting show_pretty
will never happen. Note that since commit 44dcfe8201 ("Change
formatting of u32 back to default") show_pretty is used in tc/f_u32.c
so this is first place where -pretty introduced.

Furthermore other utilities like misc/ifstat.c and misc/nstat.c define
pretty variable, however only for their own purposes. They both support
JSON output and thus depend show_pretty in new_json_obj().

Assuming above use common variable to represent -pretty option, define
it in utils.c and declare in utils.h that is commonly used. Replace
show_pretty with pretty.

Fixes: a233caa0aa ("json: make pretty printing optional")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
2018-02-16 08:13:36 -08:00
Phil Sutter
6d02518fdc ifstat, nstat: Check fdopen() return value
Prevent passing NULL FILE pointer to fgets() later.

Fix both tools in a single patch since the code changes are basically
identical.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2017-08-24 14:49:43 -07:00
Mike Frysinger
eca7a74219 ifstat/nstat: fix help output alignment
Some lines use tabs while others use spaces.  Use spaces everywhere.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-11-29 13:17:08 -08:00
Hangbin Liu
45a0dc164a nstat: add sctp snmp support
SCTP module was not load by default. But this should be OK since we will not
load table if fdopen() failed, also opening the proc file won't load SCTP
kernel module.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2016-09-08 14:29:36 -07:00
Anuradha Karuppiah
d721a14590 json_writer: Removed automatic json-object type from the constructor
Top level can be any json type and can be created using
jsonw_start_object/jsonw_end_object etc.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2016-07-20 12:02:02 -07:00
Phil Sutter
62000e51e0 Use ARRAY_SIZE macro everywhere
This patch was generated by the following semantic patch (a trimmed down
version of what is shipped with Linux sources):

@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)

The only manual adjustment was to include utils.h in misc/nstat.c to make
the macro known there.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-06-29 09:18:18 -07:00
Stephen Hemminger
acd1e437be misc: fix style issues
More checkpatch spring cleaning
2016-03-21 11:56:36 -07:00
Phil Sutter
dd81ee04ed 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>
2016-03-06 12:49:05 -08:00
Phil Sutter
d572ed4d0a get rid of remaining -Wunused-result warnings
Although not fundamentally necessary to check return codes in these
spots, preventing the warnings will put new ones into focus.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-11-29 11:48:24 -08:00
Stephen Hemminger
fcc16c2287 provide common json output formatter
Formatting JSON is moderately painful.
Provide a simple API to do the syntax formatting.
2015-08-23 10:05:29 -07:00
Eric Dumazet
d471791427 iproute2/nstat: Bug in displaying icmp stats
On Fri, 2014-12-05 at 17:13 -0800, Eric Dumazet wrote:

> I guess we could count number of spaces/fields in both lines,
> and disable the iproute2 trick if counts match.

Something like that maybe ?

 misc/nstat.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
Tested-by: Vijay Subramanian <subramanian.vijay@gmail.com>
2014-12-09 20:33:32 -08:00
Eric Dumazet
cdb2227e9c nstat: 64bit support on 32bit arches
SNMP counters can be provided as 64bit numbers.
nstat needs to cope with this even if running in 32bit mode.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2014-08-29 00:13:36 -07:00
Stephen Hemminger
404582c8eb nstat: revise json output
Also add long options
2013-09-24 11:54:45 -07:00
Stephen Hemminger
d48ed3f451 nstat: add json output format
New command line flag to output statistics in JSON format.
In our envrionment, we have scripts that parse output of commands.
It is better to use a format supported by existing parsers.
2013-09-13 10:31:41 -07:00
Stephen Hemminger
d1f28cf181 ip: make local functions static 2013-02-12 11:38:35 -08:00
Dan McGee
9a230771c0 ensure uptime is initialized if /proc/uptime cannot be opened 2011-08-31 12:16:36 -07:00
Stephen Hemminger
896ebd6c70 Fix warning about sprintf() and NSTAT_HIST
The environment variable could contain format characters, causing
problems. Better to just use it directly.
2009-12-26 10:21:13 -08:00
Mike Frysinger
a7a9ddbb67 arpd/ifstat/nstat/rtacct: use daemon()
A bunch of misc utils basically reimplement the daemon() function (the
whole fork/close/chdir/etc...).  Rather than do that, use daemon() as
that will work under nommu Linux systems that lack fork().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2009-11-10 10:41:44 -08:00
Yu Zhiguo
4ffc44ca7c Fix generic_proc_open() of command 'nstat' and 'rtacct'
Fix a bug of generic_proc_open(), so environment variables
(e.g. PROC_NET_SNMP, PROC_NET_RTACCT) can be used to specify procfile.

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>
2008-06-23 14:04:29 -07:00
Stephen Hemminger
ae665a522b Remove trailing whitespace
Go through source files and remove all trailing whitespace

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
2006-12-05 10:10:22 -08:00
shemminger
737f15f6da Thomas's ematch fixes for lex.
Fix more GCC signedness warnings.
2005-07-08 22:08:47 +00:00
net[shemminger]!shemminger
b482ffa6a6 Import patch nstat.eml
(Logical change 1.97)
2004-10-19 20:02:59 +00:00
osdl.org!shemminger
aba5acdfdb (Logical change 1.3) 2004-04-15 20:56:59 +00:00
osdl.org!shemminger
86fdf0e47b Initial revision 2004-04-15 20:56:59 +00:00