]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip: Use single variable to represent -pretty
authorSerhey Popovych <serhe.popovych@gmail.com>
Thu, 15 Feb 2018 18:31:33 +0000 (20:31 +0200)
committerDavid Ahern <dsahern@gmail.com>
Fri, 16 Feb 2018 16:13:36 +0000 (08:13 -0800)
After commit a233caa0aaee ("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 44dcfe820185 ("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: a233caa0aaee ("json: make pretty printing optional")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
include/json_print.h
ip/ip.c
lib/json_print.c
lib/utils.c
misc/ifstat.c
misc/nstat.c
tc/f_u32.c
tc/tc.c

index 45a817ce6b9a9ac8be363191e2c2564235521b01..2ca7830adbd6cfb6f89e690a419fa7da35894e56 100644 (file)
@@ -15,8 +15,6 @@
 #include "json_writer.h"
 #include "color.h"
 
-extern int show_pretty;
-
 json_writer_t *get_json_writer(void);
 
 /*
diff --git a/ip/ip.c b/ip/ip.c
index 233a9d772492a0cff28eaece88c95ef792f021fc..f6248846ef4ce8f8808cc63af86db233260c3417 100644 (file)
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -31,7 +31,6 @@ int show_stats;
 int show_details;
 int oneline;
 int brief;
-int show_pretty;
 int json;
 int timestamp;
 const char *_SL_;
@@ -261,7 +260,7 @@ int main(int argc, char **argv)
                } else if (matches(opt, "-json") == 0) {
                        ++json;
                } else if (matches(opt, "-pretty") == 0) {
-                       ++show_pretty;
+                       ++pretty;
                } else if (matches(opt, "-rcvbuf") == 0) {
                        unsigned int size;
 
index b507b14ba27f101b761049ef835a029493b75870..bda7293350c33907c64ce3ad8fcbbf4d0f73e5ee 100644 (file)
@@ -28,7 +28,7 @@ void new_json_obj(int json)
                        perror("json object");
                        exit(1);
                }
-               if (show_pretty)
+               if (pretty)
                        jsonw_pretty(_jw, true);
                jsonw_start_array(_jw);
        }
index d86c2eec3d582bcd8b07f99d4e2cff9f7d90d97c..cbe5d8de8f594f3ca60c066ec1aca847e3bcfab2 100644 (file)
@@ -37,6 +37,7 @@
 
 int resolve_hosts;
 int timestamp_short;
+int pretty;
 
 int read_prop(const char *dev, char *prop, long *value)
 {
index ac3eff6b870a9fc7f496a1e0e2ffe673b3930e48..50b906e86d5d08e20b8d995e992634cd5f9b4be2 100644 (file)
@@ -45,7 +45,6 @@ int no_update;
 int scan_interval;
 int time_constant;
 int show_errors;
-int pretty;
 double W;
 char **patterns;
 int npatterns;
index a4dd405d43a93e86e712475eb3b9e3e733bee839..ffa14b1e159608db86a718c90582b07521d92749 100644 (file)
@@ -37,7 +37,6 @@ int reset_history;
 int ignore_history;
 int no_output;
 int json_output;
-int pretty;
 int no_update;
 int scan_interval;
 int time_constant;
index 019d56c653a4afc076bf30945c598bf71ff29158..b6064cdb94cba5987238880f6c5765bad92aa04a 100644 (file)
@@ -25,8 +25,6 @@
 #include "utils.h"
 #include "tc_util.h"
 
-extern int show_pretty;
-
 static void explain(void)
 {
        fprintf(stderr,
@@ -965,7 +963,7 @@ static void show_keys(FILE *f, const struct tc_u32_key *key)
 {
        int i = 0;
 
-       if (!show_pretty)
+       if (!pretty)
                goto show_k;
 
        for (i = 0; i < ARRAY_SIZE(u32_pprinters); i++) {
diff --git a/tc/tc.c b/tc/tc.c
index aba5c101739c32ac3dc084c84d04a578effd8563..cfccf8750562f4ce76a269b7480170ce99c95c12 100644 (file)
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -33,7 +33,6 @@
 int show_stats;
 int show_details;
 int show_raw;
-int show_pretty;
 int show_graph;
 int timestamp;
 
@@ -42,7 +41,6 @@ int use_iec;
 int force;
 bool use_names;
 int json;
-int pretty;
 
 static char *conf_file;
 
@@ -449,7 +447,7 @@ int main(int argc, char **argv)
                } else if (matches(argv[1], "-raw") == 0) {
                        ++show_raw;
                } else if (matches(argv[1], "-pretty") == 0) {
-                       ++show_pretty;
+                       ++pretty;
                } else if (matches(argv[1], "-graph") == 0) {
                        show_graph = 1;
                } else if (matches(argv[1], "-Version") == 0) {
@@ -485,8 +483,6 @@ int main(int argc, char **argv)
                        ++timestamp_short;
                } else if (matches(argv[1], "-json") == 0) {
                        ++json;
-               } else if (matches(argv[1], "-pretty") == 0) {
-                       ++pretty;
                } else {
                        fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
                        return -1;