summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/bpf/bpftool/common.c31
-rw-r--r--tools/bpf/bpftool/main.h34
2 files changed, 34 insertions, 31 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index f0288269dae8..aa7017098b2a 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -50,6 +50,37 @@
50 50
51#include "main.h" 51#include "main.h"
52 52
53void p_err(const char *fmt, ...)
54{
55 va_list ap;
56
57 va_start(ap, fmt);
58 if (json_output) {
59 jsonw_start_object(json_wtr);
60 jsonw_name(json_wtr, "error");
61 jsonw_vprintf_enquote(json_wtr, fmt, ap);
62 jsonw_end_object(json_wtr);
63 } else {
64 fprintf(stderr, "Error: ");
65 vfprintf(stderr, fmt, ap);
66 fprintf(stderr, "\n");
67 }
68 va_end(ap);
69}
70
71void p_info(const char *fmt, ...)
72{
73 va_list ap;
74
75 if (json_output)
76 return;
77
78 va_start(ap, fmt);
79 vfprintf(stderr, fmt, ap);
80 fprintf(stderr, "\n");
81 va_end(ap);
82}
83
53static bool is_bpffs(char *path) 84static bool is_bpffs(char *path)
54{ 85{
55 struct statfs st_fs; 86 struct statfs st_fs;
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index d315d01be645..ff5ad05b137b 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -71,6 +71,9 @@ extern const char *bin_name;
71extern json_writer_t *json_wtr; 71extern json_writer_t *json_wtr;
72extern bool json_output; 72extern bool json_output;
73 73
74void p_err(const char *fmt, ...);
75void p_info(const char *fmt, ...);
76
74bool is_prefix(const char *pfx, const char *str); 77bool is_prefix(const char *pfx, const char *str);
75void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); 78void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
76void usage(void) __attribute__((noreturn)); 79void usage(void) __attribute__((noreturn));
@@ -97,35 +100,4 @@ int prog_parse_fd(int *argc, char ***argv);
97void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes); 100void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes);
98void print_hex_data_json(uint8_t *data, size_t len); 101void print_hex_data_json(uint8_t *data, size_t len);
99 102
100static inline void p_err(const char *fmt, ...)
101{
102 va_list ap;
103
104 va_start(ap, fmt);
105 if (json_output) {
106 jsonw_start_object(json_wtr);
107 jsonw_name(json_wtr, "error");
108 jsonw_vprintf_enquote(json_wtr, fmt, ap);
109 jsonw_end_object(json_wtr);
110 } else {
111 fprintf(stderr, "Error: ");
112 vfprintf(stderr, fmt, ap);
113 fprintf(stderr, "\n");
114 }
115 va_end(ap);
116}
117
118static inline void p_info(const char *fmt, ...)
119{
120 va_list ap;
121
122 if (json_output)
123 return;
124
125 va_start(ap, fmt);
126 vfprintf(stderr, fmt, ap);
127 fprintf(stderr, "\n");
128 va_end(ap);
129}
130
131#endif 103#endif