Skip to content

Commit

Permalink
Merge pull request #6838 from kgibm/issue6837
Browse files Browse the repository at this point in the history
Print informational message when kernel.core_pattern is piped
  • Loading branch information
babsingh committed Jan 24, 2023
2 parents 05f991b + c86a380 commit d9f0697
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 34 deletions.
5 changes: 4 additions & 1 deletion nls/portnls.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2005 IBM Corp. and others
* Copyright (c) 1991, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -170,5 +170,8 @@
#define J9NLS_PORT_DUMP_PATH_EXISTS__MODULE 0x504f5254
#define J9NLS_PORT_DUMP_PATH_EXISTS__ID 48
#define J9NLS_PORT_DUMP_PATH_EXISTS J9NLS_PORT_DUMP_PATH_EXISTS__MODULE, J9NLS_PORT_DUMP_PATH_EXISTS__ID
#define J9NLS_PORT_LINUXDUMP_PIPE_CORE_NOT_FOUND__MODULE 0x504f5254
#define J9NLS_PORT_LINUXDUMP_PIPE_CORE_NOT_FOUND__ID 49
#define J9NLS_PORT_LINUXDUMP_PIPE_CORE_NOT_FOUND J9NLS_PORT_LINUXDUMP_PIPE_CORE_NOT_FOUND__MODULE, J9NLS_PORT_LINUXDUMP_PIPE_CORE_NOT_FOUND__ID

#endif
87 changes: 54 additions & 33 deletions port/linux/omrosdump_helpers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2022 IBM Corp. and others
* Copyright (c) 1991, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -131,11 +131,13 @@ uintptr_t
renameDump(struct OMRPortLibrary *portLibrary, char *filename, pid_t pid, int signalNumber)
{
char tempPath[PATH_MAX];
char corePatternFormatOriginal[PATH_MAX];
char corePatternFormat[PATH_MAX];
char coreUsesPIDBuffer[PATH_MAX];
char derivedAbsoluteCorePath[PATH_MAX];
const char *corePatternFileName = "/proc/sys/kernel/core_pattern";
const char *coreUsesPIDFileName = "/proc/sys/kernel/core_uses_pid";
BOOLEAN corePatternPiped = FALSE;
BOOLEAN coreUsesPID = FALSE;
intptr_t procRC = -1;
intptr_t waitCoreRC = -1;
Expand All @@ -144,29 +146,34 @@ renameDump(struct OMRPortLibrary *portLibrary, char *filename, pid_t pid, int si
intptr_t renameRC = -1;
struct stat attrBuf;

memset(corePatternFormatOriginal, 0, sizeof(corePatternFormatOriginal));
memset(corePatternFormat, 0, sizeof(corePatternFormat));

procRC = getContentsFromProcFileSystem(portLibrary, corePatternFileName, corePatternFormat, PATH_MAX);
procRC = getContentsFromProcFileSystem(portLibrary, corePatternFileName, corePatternFormatOriginal, PATH_MAX);
if (0 == procRC) {
/* corePatternFormat contains format, strip out the '\n' */
char *newLine = strchr(corePatternFormat, '\n');
/* corePatternFormatOriginal contains format, strip out the '\n' */
char *newLine = strchr(corePatternFormatOriginal, '\n');
if (NULL != newLine) {
*newLine = '\0';
}
if ('|' == corePatternFormat[0]) {
if ('|' == corePatternFormatOriginal[0]) {
/*
* core pattern is being used to pipe the core file to a tool such as ABRT. In
* this case, the file is in core.<pid>
* core pattern is being used to pipe the core file to a tool such as systemd-coredump. It's
* possible that tool might write the dump to the current directory, so update corePatternFormat
* to check for this behavior.
*/
portLibrary->nls_printf(portLibrary, J9NLS_WARNING | J9NLS_STDERR, J9NLS_PORT_LINUXDUMP_PIPE_CORE, corePatternFileName, corePatternFormat, pid);
corePatternPiped = TRUE;
portLibrary->nls_printf(portLibrary, J9NLS_WARNING | J9NLS_STDERR, J9NLS_PORT_LINUXDUMP_PIPE_CORE, corePatternFileName, corePatternFormatOriginal, pid);
strncpy(corePatternFormat, "core", PATH_MAX);
} else {
strncpy(corePatternFormat, corePatternFormatOriginal, PATH_MAX);
}
} else if (1 == procRC) {
/* corePatternFileName does not exist (it should be there from kernel 2.5 onwards), use the default core file name */
strncpy(corePatternFormat, "core", PATH_MAX);
} else {
/* there was an error opening corePatternFileName */
portLibrary->str_printf(portLibrary, filename, EsMaxPath, "Error opening \"%s\". Look for core file generated by child process with pid = %i", corePatternFileName, pid);
portLibrary->str_printf(portLibrary, filename, EsMaxPath, "Error opening \"%s\". Look for core file generated by child process with pid = %i", corePatternFileName, pid);
return 1;
}

Expand All @@ -180,12 +187,13 @@ renameDump(struct OMRPortLibrary *portLibrary, char *filename, pid_t pid, int si
/* coreUsesPIDFileName does not exist, we should not get here */
} else {
/* there was an error opening coreUsesPIDFileName */
portLibrary->str_printf(portLibrary,
filename,
EsMaxPath,
"Error opening \"%s\". Look for core file generated by child process with pid = %i",
coreUsesPIDFileName,
pid);
portLibrary->str_printf(
portLibrary,
filename,
EsMaxPath,
"Error opening \"%s\". Look for core file generated by child process with pid = %i",
coreUsesPIDFileName,
pid);
return 1;
}

Expand All @@ -206,33 +214,46 @@ renameDump(struct OMRPortLibrary *portLibrary, char *filename, pid_t pid, int si

if (0 != createCoreFileNameRC) {
/* we could not derive the name from core_pattern */
portLibrary->str_printf(portLibrary,
filename,
EsMaxPath,
"Unable to derive system core filename from pattern in %s: \"%s\". "
"%s"
" Look for core file generated by child process with pid = %i",
corePatternFileName,
corePatternFormat,
derivedAbsoluteCorePath,
pid);
portLibrary->str_printf(
portLibrary,
filename,
EsMaxPath,
"Unable to derive system core filename from pattern in %s: \"%s\". "
"%s"
" Look for core file generated by child process with pid = %i",
corePatternFileName,
corePatternFormat,
derivedAbsoluteCorePath,
pid);
return 1;
}

/* wait until the core file is created, or timeout */
waitCoreRC = waitCore(derivedAbsoluteCorePath);
if (0 != waitCoreRC) {
/* the core file does not exist, bail */
portLibrary->str_printf(portLibrary,
filename,
EsMaxPath,
"The core file created by child process with pid = %i was not found. Expected to find core file with name \"%s\"",
pid,
derivedAbsoluteCorePath);
if (corePatternPiped) {
/* Nothing inherently wrong with using a core pipe program, so direct the user to its man page. */
portLibrary->nls_printf(
portLibrary,
J9NLS_INFO | J9NLS_STDERR,
J9NLS_PORT_LINUXDUMP_PIPE_CORE_NOT_FOUND,
pid,
corePatternFileName,
corePatternFormatOriginal);
} else {
portLibrary->str_printf(
portLibrary,
filename,
EsMaxPath,
"The core file created by child process with pid = %i was not found. Expected to find core file with name \"%s\"",
pid,
derivedAbsoluteCorePath);
}
return 1;
}

/* at this point we know the file in derivedCorePath exists */
/* at this point we know the file in derivedAbsoluteCorePath exists */

#ifdef DUMP_DBG
{
Expand Down Expand Up @@ -290,7 +311,7 @@ renameDump(struct OMRPortLibrary *portLibrary, char *filename, pid_t pid, int si
strcat(tempPath, filename);
}
/* message warning that the -Xdump option was not fully honoured */
portLibrary->tty_printf(portLibrary, "Warning: unable to move dump to \"%s\" across file systems (check kernel core_pattern). Using alternate file location \"%s\"\n",
portLibrary->tty_printf(portLibrary, "Warning: unable to move dump to \"%s\" across file systems (check kernel core_pattern). Using alternate file location \"%s\"\n",
filename, tempPath);
/* copy the new file destination back into the supplied filename for the RAS messages */
portLibrary->str_printf(portLibrary, filename, EsMaxPath, "%s", tempPath);
Expand Down

0 comments on commit d9f0697

Please sign in to comment.