bpftool: Wrap struct_ops dump in an array
authorManu Bretelle <chantr4@gmail.com>
Wed, 18 Oct 2023 23:01:33 +0000 (16:01 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 19 Oct 2023 14:30:15 +0000 (16:30 +0200)
commit6bd5e167af2e9d1aa79e4a1a2598abcdc8fafd59
tree26269f8535c6e4ab0da210d580c6c4f7a6c3da8a
parent90704b4be0b0d6d0a7a9369d4b9aae6a579602c7
bpftool: Wrap struct_ops dump in an array

When dumping a struct_ops, 2 dictionaries are emitted.

When using `name`, they were already wrapped in an array, but not when
using `id`. Causing `jq` to fail at parsing the payload as it reached
the comma following the first dict.

This change wraps those dictionaries in an array so valid json is emitted.

Before, jq fails to parse the output:
```
 $ sudo bpftool struct_ops dump id 1523612 | jq . > /dev/null
parse error: Expected value before ',' at line 19, column 2
```

After, no error parsing the output:
```
sudo ./bpftool  struct_ops dump id 1523612 | jq . > /dev/null
```

Signed-off-by: Manu Bretelle <chantr4@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20231018230133.1593152-3-chantr4@gmail.com
tools/bpf/bpftool/struct_ops.c