bpftool: Handle EAGAIN error code properly in pids collection
authorYonghong Song <yhs@fb.com>
Tue, 18 Aug 2020 22:23:12 +0000 (15:23 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 19 Aug 2020 00:36:23 +0000 (17:36 -0700)
When the error code is EAGAIN, the kernel signals the user
space should retry the read() operation for bpf iterators.
Let us do it.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200818222312.2181675-1-yhs@fb.com
tools/bpf/bpftool/pids.c

index e3b1163..df7d8ec 100644 (file)
@@ -134,6 +134,8 @@ int build_obj_refs_table(struct obj_refs_table *table, enum bpf_obj_type type)
        while (true) {
                ret = read(fd, buf, sizeof(buf));
                if (ret < 0) {
+                       if (errno == EAGAIN)
+                               continue;
                        err = -errno;
                        p_err("failed to read PID iterator output: %d", err);
                        goto out;