libbcc-py: Fix libbpf types
authorMauricio Vásquez <mauricio@kinvolk.io>
Thu, 21 May 2020 15:22:30 +0000 (10:22 -0500)
committeryonghong-song <ys114321@gmail.com>
Thu, 21 May 2020 19:34:05 +0000 (12:34 -0700)
1ad2656a1d9c ("Add support_kfunc function to BPF object") added new functions
to libbcc-py but didn't set the restype and argstypes for those. It's causing
the `bpf_has_kernel_btf` function to return True in systems without support
for BTF, making tools like opensnoop, klockstat and any other using kfuncs
unusable in those systems.

The following Python script reproduces the problem:

```
from bcc import BPF
print(BPF.support_kfunc())
```

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
src/python/bcc/libbcc.py

index d2c4d2e..f35b15c 100644 (file)
@@ -108,6 +108,10 @@ lib.bpf_detach_tracepoint.restype = ct.c_int
 lib.bpf_detach_tracepoint.argtypes = [ct.c_char_p, ct.c_char_p]
 lib.bpf_attach_raw_tracepoint.restype = ct.c_int
 lib.bpf_attach_raw_tracepoint.argtypes = [ct.c_int, ct.c_char_p]
+lib.bpf_attach_kfunc.restype = ct.c_int
+lib.bpf_attach_kfunc.argtypes = [ct.c_int]
+lib.bpf_has_kernel_btf.restype = ct.c_bool
+lib.bpf_has_kernel_btf.argtypes = None
 lib.bpf_open_perf_buffer.restype = ct.c_void_p
 lib.bpf_open_perf_buffer.argtypes = [_RAW_CB_TYPE, _LOST_CB_TYPE, ct.py_object, ct.c_int, ct.c_int, ct.c_int]
 lib.bpf_open_perf_event.restype = ct.c_int