All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode
@ 2018-02-15  6:42 Jakub Kicinski
  2018-02-15  6:42 ` [PATCH bpf 1/2] tools: bpftool: preserve JSON for batch mode when dumping insns to file Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2018-02-15  6:42 UTC (permalink / raw)
  To: daniel, alexei.starovoitov; +Cc: netdev, oss-drivers, Jakub Kicinski

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH bpf 1/2] tools: bpftool: preserve JSON for batch mode when dumping insns to file
  2018-02-15  6:42 [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode Jakub Kicinski
@ 2018-02-15  6:42 ` Jakub Kicinski
  2018-02-15  6:42 ` [PATCH bpf 2/2] tools: bpftool: preserve JSON output on errors on batch file parsing Jakub Kicinski
  2018-02-15  9:03 ` [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2018-02-15  6:42 UTC (permalink / raw)
  To: daniel, alexei.starovoitov; +Cc: netdev, oss-drivers, Quentin Monnet

From: Quentin Monnet <quentin.monnet@netronome.com>

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 <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH bpf 2/2] tools: bpftool: preserve JSON output on errors on batch file parsing
  2018-02-15  6:42 [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode Jakub Kicinski
  2018-02-15  6:42 ` [PATCH bpf 1/2] tools: bpftool: preserve JSON for batch mode when dumping insns to file Jakub Kicinski
@ 2018-02-15  6:42 ` Jakub Kicinski
  2018-02-15  9:03 ` [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2018-02-15  6:42 UTC (permalink / raw)
  To: daniel, alexei.starovoitov; +Cc: netdev, oss-drivers, Quentin Monnet

From: Quentin Monnet <quentin.monnet@netronome.com>

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 <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode
  2018-02-15  6:42 [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode Jakub Kicinski
  2018-02-15  6:42 ` [PATCH bpf 1/2] tools: bpftool: preserve JSON for batch mode when dumping insns to file Jakub Kicinski
  2018-02-15  6:42 ` [PATCH bpf 2/2] tools: bpftool: preserve JSON output on errors on batch file parsing Jakub Kicinski
@ 2018-02-15  9:03 ` Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2018-02-15  9:03 UTC (permalink / raw)
  To: Jakub Kicinski, alexei.starovoitov; +Cc: netdev, oss-drivers

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!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-15  9:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15  6:42 [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode Jakub Kicinski
2018-02-15  6:42 ` [PATCH bpf 1/2] tools: bpftool: preserve JSON for batch mode when dumping insns to file Jakub Kicinski
2018-02-15  6:42 ` [PATCH bpf 2/2] tools: bpftool: preserve JSON output on errors on batch file parsing Jakub Kicinski
2018-02-15  9:03 ` [PATCH bpf 0/2] tools: bpftool: minor fixes for JSON in batch mode Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.