Skip to content

Commit ebcc7a7

Browse files
authored
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 <[email protected]>
1 parent 378d287 commit ebcc7a7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

libbpf-tools/javagc.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,39 @@ static int get_jvmso_path(char *path)
125125
size_t seg_start, seg_end, seg_off;
126126
FILE *f;
127127
int i = 0;
128+
bool found = false;
129+
130+
if (env.pid == -1) {
131+
fprintf(stderr, "not specify pid, see --pid.\n");
132+
return -1;
133+
}
128134

129135
sprintf(buf, "/proc/%d/maps", env.pid);
130136
f = fopen(buf, "r");
131-
if (!f)
137+
if (!f) {
138+
fprintf(stderr, "open %s failed: %m\n", buf);
132139
return -1;
140+
}
133141

134142
while (fscanf(f, "%zx-%zx %s %zx %*s %*d%[^\n]\n",
135143
&seg_start, &seg_end, mode, &seg_off, line) == 5) {
136144
i = 0;
137145
while (isblank(line[i]))
138146
i++;
139147
if (strstr(line + i, "libjvm.so")) {
148+
found = true;
149+
strcpy(path, line + i);
140150
break;
141151
}
142152
}
143153

144-
strcpy(path, line + i);
145154
fclose(f);
146155

156+
if (!found) {
157+
fprintf(stderr, "Not found libjvm.so.\n");
158+
return -ENOENT;
159+
}
160+
147161
return 0;
148162
}
149163

0 commit comments

Comments
 (0)