src/os/linux/vm/os_linux.cpp

Print this page

        

*** 5989,6005 **** } // Get the default path to the core file // Returns the length of the string int os::get_core_path(char* buffer, size_t bufferSize) { ! const char* p = get_current_directory(buffer, bufferSize); if (p == NULL) { assert(p != NULL, "failed to get current directory"); return 0; } return strlen(buffer); } /////////////// Unit tests /////////////// --- 5989,6071 ---- } // Get the default path to the core file // Returns the length of the string int os::get_core_path(char* buffer, size_t bufferSize) { ! /* ! * Max length of /proc/sys/kernel/core_pattern is 128 characters. ! * See https://www.kernel.org/doc/Documentation/sysctl/kernel.txt ! */ ! const int core_pattern_len = 129; ! char core_pattern[core_pattern_len] = {0}; + FILE *core_pattern_file = fopen("/proc/sys/kernel/core_pattern", "r"); + if (core_pattern_file != NULL) { + char *ret_ptr = fgets(core_pattern, core_pattern_len, core_pattern_file); + fclose(core_pattern_file); + + if (ret_ptr != NULL) { + char *last_char = core_pattern + strlen(core_pattern) - 1; + + if (*last_char == '\n') { + *last_char = '\0'; + } + + } + + } + + if (strlen(core_pattern) == 0) { + return 0; + } + + char *pid_pos = strstr(core_pattern, "%p"); + size_t written; + + if (core_pattern[0] == '/') { + written = jio_snprintf(buffer, bufferSize, core_pattern); + } else { + char *cwd = (char *)os::malloc(PATH_MAX, mtInternal); + if (cwd == NULL) { + return 0; + } + + const char* p = get_current_directory(cwd, PATH_MAX); if (p == NULL) { + os::free(cwd); assert(p != NULL, "failed to get current directory"); return 0; } + if (core_pattern[0] == '|') { + written = jio_snprintf(buffer, bufferSize, + "\"%s\" (or dumping to %s/core.%d)", + &core_pattern[1], p, current_process_id()); + } else { + written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern); + } + + os::free(cwd); + } + + if ((written >= 0) && (written < bufferSize) + && (pid_pos == NULL) && (core_pattern[0] != '|')) { + FILE *core_uses_pid_file = fopen("/proc/sys/kernel/core_uses_pid", "r"); + + if (core_uses_pid_file != NULL) { + int core_uses_pid = fgetc(core_uses_pid_file); + fclose(core_uses_pid_file); + + if (core_uses_pid == '1'){ + jio_snprintf(buffer + written, bufferSize - written, + ".%d", current_process_id()); + } + + } + + } + return strlen(buffer); } /////////////// Unit tests ///////////////