[PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode

STALE3108d

4 messages, 2 authors, 2018-02-15 · open the first message on its own page

[PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode

From: Jakub Kicinski <hidden>
Date: 2018-02-15 06:43:09

Quentin says:

These are two minor fixes to avoid breaking JSON output in batch mode. The
first one makes bpftool output a "null" JSON object, as expected in batch
mode if nothing else is to be printed, when dumping program instructions
into an output file. The second one replaces a call to "perror()" with
something that does not break JSON when parsing input file for batch mode.

Quentin Monnet (2):
  tools: bpftool: preserve JSON for batch mode when dumping insns to
    file
  tools: bpftool: preserve JSON output on errors on batch file parsing

 tools/bpf/bpftool/main.c | 2 +-
 tools/bpf/bpftool/prog.c | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

-- 
2.15.1

[PATCH bpf 1/2] tools: bpftool: preserve JSON for batch mode when dumping insns to file

From: Jakub Kicinski <hidden>
Date: 2018-02-15 06:43:10

From: Quentin Monnet <redacted>

Print a "null" JSON object to standard output when bpftool is used to
print program instructions to a file, so as to avoid breaking JSON
output on batch mode.

This null object was added for most commands in a previous commit, but
this specific case had been omitted.

Fixes: 004b45c0e51a ("tools: bpftool: provide JSON output for all possible commands")
Signed-off-by: Quentin Monnet <redacted>
Acked-by: Jakub Kicinski <redacted>
---
 tools/bpf/bpftool/prog.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index e8e2baaf93c2..e549e329be82 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -774,6 +774,9 @@ static int do_dump(int argc, char **argv)
 			      n < 0 ? strerror(errno) : "short write");
 			goto err_free;
 		}
+
+		if (json_output)
+			jsonw_null(json_wtr);
 	} else {
 		if (member_len == &info.jited_prog_len) {
 			const char *name = NULL;
-- 
2.15.1

[PATCH bpf 2/2] tools: bpftool: preserve JSON output on errors on batch file parsing

From: Jakub Kicinski <hidden>
Date: 2018-02-15 06:43:10

From: Quentin Monnet <redacted>

Before this patch, perror() function is used in some cases when bpftool
fails to parse its input file in batch mode. This function does not
integrate well with the rest of the output when JSON is used, so we
replace it by something that is compliant.

Most calls to perror() had already been replaced in a previous patch,
this one is a leftover.

Fixes: d319c8e101c5 ("tools: bpftool: preserve JSON output on errors on batch file parsing")
Signed-off-by: Quentin Monnet <redacted>
Acked-by: Jakub Kicinski <redacted>
---
 tools/bpf/bpftool/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 3a0396d87c42..185acfa229b5 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -244,7 +244,7 @@ static int do_batch(int argc, char **argv)
 	}
 
 	if (errno && errno != ENOENT) {
-		perror("reading batch file failed");
+		p_err("reading batch file failed: %s", strerror(errno));
 		err = -1;
 	} else {
 		p_info("processed %d lines", lines);
-- 
2.15.1

Re: [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2018-02-15 09:03:46

On 02/15/2018 07:42 AM, Jakub Kicinski wrote:
Quentin says:

These are two minor fixes to avoid breaking JSON output in batch mode. The
first one makes bpftool output a "null" JSON object, as expected in batch
mode if nothing else is to be printed, when dumping program instructions
into an output file. The second one replaces a call to "perror()" with
something that does not break JSON when parsing input file for batch mode.
Applied to bpf tree, thanks Quentin!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help