python: Print BPF syscall error if DEBUG_BPF is on but log_buf is empty.
authorQuentin Monnet <quentin.monnet@6wind.com>
Thu, 9 Jun 2016 12:55:29 +0000 (14:55 +0200)
committerQuentin Monnet <quentin.monnet@6wind.com>
Mon, 13 Jun 2016 08:55:50 +0000 (10:55 +0200)
commitbb699887b84309ecce043d6cf41b55cfb55285d3
tree5f564fb8530274fe18f3c31322f4dc2dcb9c5708
parent5815f41afff62bb176ec57a7bea3a3efc9c5f2a0
python: Print BPF syscall error if DEBUG_BPF is on but log_buf is empty.

Commit 759029fea8066b41b54be5447137db95cb1313c4 provided an option to
store the output from BPF syscall into a buffer (and not to print it
systematically to standard output) on program load in libbpf.c.

But doing so, it only stores the content of attr.log_buf, while the
error string--resulting from a failed BPF syscall--is no more displayed
when the DEBUG_BPF flag is used in the Python script responsible for
converting and injecting the code.

This commit proposes a fix for this bug by printing the error message
(associated to the return value from the syscall) from the Python
caller, when all the following conditions are met:

- the syscall fails,
- the DEBUG_BPF flag has been provided, and
- log_buf is empty (has not been filled by kernel).

Note: when DEBUG_BPF is not provided, the error string is printed in the
C wrapper in libbpf.c (bpf_prog_load) anyway.

Fixes: 759029fe ("Add option for custom log string to bpf_prog_load")

Signed-off-by: Quentin Monnet <quentin.monnet@6wind.com>
src/python/bcc/__init__.py