Skip to content
Permalink
Browse files

8234741: enhance os::get_core_path on macOS

Reviewed-by: clanger, gziemski
  • Loading branch information
Matthias Baesken
Matthias Baesken committed Nov 29, 2019
1 parent 6ba58f7 commit fec6f8a1e42e65e6be455ca36ea67baca8585037
Showing with 22 additions and 3 deletions.
  1. +22 −3 src/hotspot/os/bsd/os_bsd.cpp
@@ -3763,11 +3763,30 @@ int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
}
}

// Get the default path to the core file
// Get the kern.corefile setting, or otherwise the default path to the core file
// Returns the length of the string
int os::get_core_path(char* buffer, size_t bufferSize) {
int n = jio_snprintf(buffer, bufferSize, "/cores/core.%d", current_process_id());

int n = 0;
#ifdef __APPLE__
char coreinfo[MAX_PATH];
size_t sz = sizeof(coreinfo);
int ret = sysctlbyname("kern.corefile", coreinfo, &sz, NULL, 0);
if (ret == 0) {
char *pid_pos = strstr(coreinfo, "%P");
// skip over the "%P" to preserve any optional custom user pattern
const char* tail = (pid_pos != NULL) ? (pid_pos + 2) : "";

if (pid_pos != NULL) {
*pid_pos = '\0';
n = jio_snprintf(buffer, bufferSize, "%s%d%s", coreinfo, os::current_process_id(), tail);
} else {
n = jio_snprintf(buffer, bufferSize, "%s", coreinfo);
}
} else
#endif
{
n = jio_snprintf(buffer, bufferSize, "/cores/core.%d", os::current_process_id());
}
// Truncate if theoretical string was longer than bufferSize
n = MIN2(n, (int)bufferSize);

0 comments on commit fec6f8a

Please sign in to comment.
You can’t perform that action at this time.