8207832: serviceability/sa/ClhsdbCDSCore.java failed with "Couldn't find core file location"

Handle %p in /proc/sys/kernel/core_pattern

Reviewed-by: dholmes, hseigel
This commit is contained in:
Ioi Lam 2018-08-15 19:22:46 -07:00
parent e12ee81ff0
commit bd57506f87
3 changed files with 16 additions and 2 deletions

View file

@ -5793,11 +5793,21 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
core_pattern[ret] = '\0';
}
// Replace the %p in the core pattern with the process id. NOTE: we do this
// only if the pattern doesn't start with "|", and we support only one %p in
// the pattern.
char *pid_pos = strstr(core_pattern, "%p");
const char* tail = (pid_pos != NULL) ? (pid_pos + 2) : ""; // skip over the "%p"
int written;
if (core_pattern[0] == '/') {
written = jio_snprintf(buffer, bufferSize, "%s", core_pattern);
if (pid_pos != NULL) {
*pid_pos = '\0';
written = jio_snprintf(buffer, bufferSize, "%s%d%s", core_pattern,
current_process_id(), tail);
} else {
written = jio_snprintf(buffer, bufferSize, "%s", core_pattern);
}
} else {
char cwd[PATH_MAX];
@ -5810,6 +5820,10 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
written = jio_snprintf(buffer, bufferSize,
"\"%s\" (or dumping to %s/core.%d)",
&core_pattern[1], p, current_process_id());
} else if (pid_pos != NULL) {
*pid_pos = '\0';
written = jio_snprintf(buffer, bufferSize, "%s/%s%d%s", p, core_pattern,
current_process_id(), tail);
} else {
written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
}