[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1643645554-28723-4-git-send-email-alan.maguire@oracle.com>
Date: Mon, 31 Jan 2022 16:12:33 +0000
From: Alan Maguire <alan.maguire@...cle.com>
To: andrii@...nel.org, ast@...nel.org, daniel@...earbox.net
Cc: kafai@...com, songliubraving@...com, yhs@...com,
john.fastabend@...il.com, kpsingh@...nel.org, jolsa@...nel.org,
sunyucong@...il.com, netdev@...r.kernel.org, bpf@...r.kernel.org,
Alan Maguire <alan.maguire@...cle.com>
Subject: [PATCH v3 bpf-next 3/4] selftests/bpf: add get_lib_path() helper
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) {
+ 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