libbpf-tools: fix EINTR related issues
authorMauricio Vásquez <mauricio@kinvolk.io>
Fri, 17 Sep 2021 14:40:41 +0000 (09:40 -0500)
committerMauricio Vásquez <mauricio@kinvolk.io>
Fri, 24 Sep 2021 12:11:05 +0000 (07:11 -0500)
commit695e12765d6c84ccda3614088ea3aaeba345ee44
tree31b32eb27ad4ff755845ba88f6504090d3c3612d
parent45c6ae9eb46fde378bdfe87e42b92356170b8c76
libbpf-tools: fix EINTR related issues

1. Most of the tools that use perf_buffer__poll() were not handling the
case when it was interrupted by a signal, they were just ending.
We noticed this issue by running the tools inside a container, after
some seconds they will finish:

```
$ time /execsnoop
...
runc             210198 939      0 /usr/sbin/runc --version
docker-init      210205 939      0 /usr/bin/docker-init --version
Error polling perf buffer: -4

real 0m48.913s
user 0m0.020s
sys 0m0.033s
```

This commit fixes that by checking if errno is EINTR after calling
perf_buffer__poll().

2. Many tools were returning non zero when ended by SIG_INT.

```
$ sudo ./execsnoop
PCOMM            PID    PPID   RET ARGS
runc             203967 939      0 /usr/sbin/runc --version
docker-init      203973 939      0 /usr/bin/docker-init --version
calico           203974 724      0 /opt/cni/bin/calico
portmap          203985 724      0 /opt/cni/bin/portmap
bandwidth        203990 724      0 /opt/cni/bin/bandwidth
^C
$ echo $?
130
```

3. Some tools were missing the SIG_INT handler

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
17 files changed:
libbpf-tools/bindsnoop.c
libbpf-tools/biosnoop.c
libbpf-tools/drsnoop.c
libbpf-tools/execsnoop.c
libbpf-tools/exitsnoop.c
libbpf-tools/filelife.c
libbpf-tools/filetop.c
libbpf-tools/fsslower.c
libbpf-tools/gethostlatency.c
libbpf-tools/ksnoop.c
libbpf-tools/mountsnoop.c
libbpf-tools/opensnoop.c
libbpf-tools/runqslower.c
libbpf-tools/solisten.c
libbpf-tools/statsnoop.c
libbpf-tools/tcpconnect.c
libbpf-tools/tcpconnlat.c