[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzbyWd6bfWFGLX-c7s2YLjFTQXAc=NOEFChwu2ApvJNeFQ@mail.gmail.com>
Date: Fri, 4 Feb 2022 11:24:17 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alan Maguire <alan.maguire@...cle.com>
Cc: Andrii Nakryiko <andrii@...nel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Martin Lau <kafai@...com>, Song Liu <songliubraving@...com>,
Yonghong Song <yhs@...com>,
john fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Jiri Olsa <jolsa@...nel.org>,
Yucong Sun <sunyucong@...il.com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>
Subject: Re: [PATCH v3 bpf-next 3/4] selftests/bpf: add get_lib_path() helper
On Mon, Jan 31, 2022 at 8:13 AM Alan Maguire <alan.maguire@...cle.com> wrote:
>
> get_lib_path(path_substr) returns full path to a library
> containing path_substr (such as "libc-") found via
> /proc/self/maps. Caller is responsible for freeing
> the returned string.
>
> Signed-off-by: Alan Maguire <alan.maguire@...cle.com>
> ---
> tools/testing/selftests/bpf/trace_helpers.c | 17 +++++++++++++++++
> tools/testing/selftests/bpf/trace_helpers.h | 2 ++
> 2 files changed, 19 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
> index ca6abae..49e5f0d 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.c
> +++ b/tools/testing/selftests/bpf/trace_helpers.c
> @@ -216,3 +216,20 @@ ssize_t get_rel_offset(uintptr_t addr)
> fclose(f);
> return -EINVAL;
> }
> +
> +char *get_lib_path(const char *path_substr)
> +{
> + char *found = NULL;
> + char lib_path[512];
> + FILE *f;
> +
> + f = fopen("/proc/self/maps", "r");
> + while (fscanf(f, "%*s %*s %*s %*s %*s %[^\n]", lib_path) == 1) {
I think it can be followed by " (deleted)", right? Do we want to
detect that and do something about it?
> + if (strstr(lib_path, path_substr) == NULL)
> + continue;
> + found = strdup(lib_path);
> + break;
> + }
> + fclose(f);
> + return found;
> +}
> diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
> index 238a9c9..ff379f6 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.h
> +++ b/tools/testing/selftests/bpf/trace_helpers.h
> @@ -20,5 +20,7 @@ struct ksym {
>
> ssize_t get_uprobe_offset(const void *addr);
> ssize_t get_rel_offset(uintptr_t addr);
> +/* Return allocated string path to library that contains path_substr. */
> +char *get_lib_path(const char *path_substr);
>
> #endif
> --
> 1.8.3.1
>
Powered by blists - more mailing lists