From ebcc7a72be22dbf570104a86d94f6ffd755ee618 Mon Sep 17 00:00:00 2001 From: Rong Tao Date: Sun, 24 Nov 2024 02:44:28 +0800 Subject: [PATCH] libbpf-tools: javagc: Hints for more information (#5154) Prints a prompt message for not finding jvm.so and opening /proc/PID/maps incorrectly. Signed-off-by: Rong Tao --- libbpf-tools/javagc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libbpf-tools/javagc.c b/libbpf-tools/javagc.c index 8979d8f6e146..c3630105a6ff 100644 --- a/libbpf-tools/javagc.c +++ b/libbpf-tools/javagc.c @@ -125,11 +125,19 @@ static int get_jvmso_path(char *path) size_t seg_start, seg_end, seg_off; FILE *f; int i = 0; + bool found = false; + + if (env.pid == -1) { + fprintf(stderr, "not specify pid, see --pid.\n"); + return -1; + } sprintf(buf, "/proc/%d/maps", env.pid); f = fopen(buf, "r"); - if (!f) + if (!f) { + fprintf(stderr, "open %s failed: %m\n", buf); return -1; + } while (fscanf(f, "%zx-%zx %s %zx %*s %*d%[^\n]\n", &seg_start, &seg_end, mode, &seg_off, line) == 5) { @@ -137,13 +145,19 @@ static int get_jvmso_path(char *path) while (isblank(line[i])) i++; if (strstr(line + i, "libjvm.so")) { + found = true; + strcpy(path, line + i); break; } } - strcpy(path, line + i); fclose(f); + if (!found) { + fprintf(stderr, "Not found libjvm.so.\n"); + return -ENOENT; + } + return 0; }