Skip to contentSkip to conversation

bpftool: Fix bpftool net output

PATCH Applied Andrey Ignatov 3 participants 3 messages Sep 26, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpftool: Fix bpftool net output

Print bpftool net output to stdout instead of stderr. Only errors should be printed to stderr. Regular output should go to stdout and this is what all other subcommands of bpftool do, including --json and --pretty formats of bpftool net itself.

Fixes commit f6f3bac08ff9 ("tools/bpf: bpftool: add net support")
---
 tools/bpf/bpftool/netlink_dumper.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tools/bpf/bpftool/netlink_dumper.h +9 -9
index 0788cfbbed0e..e3516b586a34 100644
@@ -16,7 +16,7 @@
 		jsonw_name(json_wtr, name);		\
 		jsonw_start_object(json_wtr);		\
 	} else {					\
-		fprintf(stderr, "%s {", name);		\
+		fprintf(stdout, "%s {", name);		\
 	}						\
 }
 
@@ -25,7 +25,7 @@
 	if (json_output)				\
 		jsonw_start_object(json_wtr);		\
 	else						\
-		fprintf(stderr, "{");			\
+		fprintf(stdout, "{");			\
 }
 
 #define NET_END_OBJECT_NESTED				\
@@ -33,7 +33,7 @@
 	if (json_output)				\
 		jsonw_end_object(json_wtr);		\
 	else						\
-		fprintf(stderr, "}");			\
+		fprintf(stdout, "}");			\
 }
 
 #define NET_END_OBJECT					\
@@ -47,7 +47,7 @@
 	if (json_output)				\
 		jsonw_end_object(json_wtr);		\
 	else						\
-		fprintf(stderr, "\n");			\
+		fprintf(stdout, "\n");			\
 }
 
 #define NET_START_ARRAY(name, fmt_str)			\
@@ -56,7 +56,7 @@
 		jsonw_name(json_wtr, name);		\
 		jsonw_start_array(json_wtr);		\
 	} else {					\
-		fprintf(stderr, fmt_str, name);		\
+		fprintf(stdout, fmt_str, name);		\
 	}						\
 }
 
@@ -65,7 +65,7 @@
 	if (json_output)				\
 		jsonw_end_array(json_wtr);		\
 	else						\
-		fprintf(stderr, "%s", endstr);		\
+		fprintf(stdout, "%s", endstr);		\
 }
 
 #define NET_DUMP_UINT(name, fmt_str, val)		\
@@ -73,7 +73,7 @@
 	if (json_output)				\
 		jsonw_uint_field(json_wtr, name, val);	\
 	else						\
-		fprintf(stderr, fmt_str, val);		\
+		fprintf(stdout, fmt_str, val);		\
 }
 
 #define NET_DUMP_STR(name, fmt_str, str)		\
@@ -81,7 +81,7 @@
 	if (json_output)				\
 		jsonw_string_field(json_wtr, name, str);\
 	else						\
-		fprintf(stderr, fmt_str, str);		\
+		fprintf(stdout, fmt_str, str);		\
 }
 
 #define NET_DUMP_STR_ONLY(str)				\
@@ -89,7 +89,7 @@
 	if (json_output)				\
 		jsonw_string(json_wtr, str);		\
 	else						\
-		fprintf(stderr, "%s ", str);		\
+		fprintf(stdout, "%s ", str);		\
 }
 
 #endif
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrey Ignatov

Print bpftool net output to stdout instead of stderr. Only errors should be printed to stderr. Regular output should go to stdout and this is what all other subcommands of bpftool do, including --json and --pretty formats of bpftool net itself.

Fixes commit f6f3bac08ff9 ("tools/bpf: bpftool: add net support")
Quoted 92 lines
---
 tools/bpf/bpftool/netlink_dumper.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tools/bpf/bpftool/netlink_dumper.h +9 -10
index 0788cfbbed0e..e3516b586a34 100644
@@ -16,7 +16,7 @@
                jsonw_name(json_wtr, name);             \
                jsonw_start_object(json_wtr);           \
        } else {                                        \
-               fprintf(stderr, "%s {", name);          \
+               fprintf(stdout, "%s {", name);          \
        }                                               \
 }
 
@@ -25,7 +25,7 @@
        if (json_output)                                \
                jsonw_start_object(json_wtr);           \
        else                                            \
-               fprintf(stderr, "{");                   \
+               fprintf(stdout, "{");                   \
 }
 
 #define NET_END_OBJECT_NESTED                          \
@@ -33,7 +33,7 @@
        if (json_output)                                \
                jsonw_end_object(json_wtr);             \
        else                                            \
-               fprintf(stderr, "}");                   \
+               fprintf(stdout, "}");                   \
 }
 
 #define NET_END_OBJECT                                 \
@@ -47,7 +47,7 @@
        if (json_output)                                \
                jsonw_end_object(json_wtr);             \
        else                                            \
-               fprintf(stderr, "\n");                  \
+               fprintf(stdout, "\n");                  \
 }
 
 #define NET_START_ARRAY(name, fmt_str)                 \
@@ -56,7 +56,7 @@
                jsonw_name(json_wtr, name);             \
                jsonw_start_array(json_wtr);            \
        } else {                                        \
-               fprintf(stderr, fmt_str, name);         \
+               fprintf(stdout, fmt_str, name);         \
        }                                               \
 }
 
@@ -65,7 +65,7 @@
        if (json_output)                                \
                jsonw_end_array(json_wtr);              \
        else                                            \
-               fprintf(stderr, "%s", endstr);          \
+               fprintf(stdout, "%s", endstr);          \
 }
 
 #define NET_DUMP_UINT(name, fmt_str, val)              \
@@ -73,7 +73,7 @@
        if (json_output)                                \
                jsonw_uint_field(json_wtr, name, val);  \
        else                                            \
-               fprintf(stderr, fmt_str, val);          \
+               fprintf(stdout, fmt_str, val);          \
 }
 
 #define NET_DUMP_STR(name, fmt_str, str)               \
@@ -81,7 +81,7 @@
        if (json_output)                                \
                jsonw_string_field(json_wtr, name, str);\
        else                                            \
-               fprintf(stderr, fmt_str, str);          \
+               fprintf(stdout, fmt_str, str);          \
 }
 
 #define NET_DUMP_STR_ONLY(str)                         \
@@ -89,7 +89,7 @@
        if (json_output)                                \
                jsonw_string(json_wtr, str);            \
        else                                            \
-               fprintf(stderr, "%s ", str);            \
+               fprintf(stdout, "%s ", str);            \
 }
 
 #endif
--

2.17.1

maintainer Applied
#2 lore raw
In reply to Andrey Ignatov
Quoted 8 lines · Andrey Ignatov

Print bpftool net output to stdout instead of stderr. Only errors should be printed to stderr. Regular output should go to stdout and this is what all other subcommands of bpftool do, including --json and --pretty formats of bpftool net itself.

Fixes commit f6f3bac08ff9 ("tools/bpf: bpftool: add net support")

Applied to bpf-next, thanks Andrey!