Skip to content

Commit

Permalink
Merge pull request #6507 from davidjmccann/use_cwd_for_opendir
Browse files Browse the repository at this point in the history
Get opendir to use the cwd if the corepath is blank
  • Loading branch information
0xdaryl committed May 26, 2022
2 parents 6843751 + 0534426 commit dc315bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
35 changes: 31 additions & 4 deletions port/aix/omrosdump_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ appendCoreName(OMRPortLibrary *portLibrary, char *corepath, intptr_t pid)
char pidFilter[24];
uintptr_t pidLen;

DIR *folder = opendir(corepath);
/* Open the core path or, if blank, the current working directory */
char *dirname = (*corepath != '\0') ? corepath : ".";
DIR *folder = opendir(dirname);

struct dirent *entry = NULL;

/* Failsafe name */
strcpy(base, "core");

if (!folder) {
#if defined(DUMP_DBG)
portLibrary->tty_printf(portLibrary, "\tappendCoreName: failed to opendir: %s, errno: %d\n", dirname, errno);
#endif /* defined(DUMP_DBG) */
return;
}

Expand All @@ -74,6 +79,10 @@ appendCoreName(OMRPortLibrary *portLibrary, char *corepath, intptr_t pid)
while ((entry = readdir(folder))) {
char *s = entry->d_name;

#if defined(DUMP_DBG)
portLibrary->tty_printf(portLibrary, "\tappendCoreName: found file: \"%s\"\n", s);
#endif /* defined(DUMP_DBG) */

/* Files beginning with "core." must contain ".<pid>",
* unless we're on AIX, in which case if core compression is enabled, they can be of the form:
* 1. start with "core.<pid>" or
Expand All @@ -97,6 +106,10 @@ appendCoreName(OMRPortLibrary *portLibrary, char *corepath, intptr_t pid)
continue;
}

#if defined(DUMP_DBG)
portLibrary->tty_printf(portLibrary, "\tappendCoreName: \"%s\" matches the pidFilter \"%s\" or is a plain \"core\" file: %s\n", s, pidFilter);
#endif /* defined(DUMP_DBG) */

/* Temporarily append current name */
strcpy(base, entry->d_name);

Expand All @@ -108,12 +121,26 @@ appendCoreName(OMRPortLibrary *portLibrary, char *corepath, intptr_t pid)
corename[63] = '\0';
lastModTime = attrBuf.st_mtime;
}
#if defined(DUMP_DBG)
else {
portLibrary->tty_printf(portLibrary, "\tappendCoreName: not a regular file: %s\n", corepath);
}
#endif /* defined(DUMP_DBG) */
}
#if defined(DUMP_DBG)
else {
portLibrary->tty_printf(portLibrary, "\tappendCoreName: failed to stat: %s, errno %d\n", corepath, errno);
}
#endif /* defined(DUMP_DBG) */
}
closedir(folder);

/* Append most likely name */
strcpy(base, corename);

#if defined(DUMP_DBG)
portLibrary->tty_printf(portLibrary, "\tappendCoreName: returning: %s\n", corepath);
#endif /* defined(DUMP_DBG) */
}

/*
Expand Down Expand Up @@ -167,7 +194,7 @@ genSystemCoreUsingGencore(struct OMRPortLibrary *portLibrary, char *filename)
coreDumpInfo.length = (unsigned int) strlen(filename);

#if defined(DUMP_DBG)
portLibrary->tty_printf(portLibrary, "\tomrdump_create: attempting to generate corefile, filename: %s\n", coreDumpInfo.name);
portLibrary->tty_printf(portLibrary, "\tomrdump_create: attempting to generate corefile, filename: %s, uid: %d, euid: %d\n", coreDumpInfo.name, getuid(), geteuid());
fflush(stdout);
#endif /* defined(DUMP_DBG) */

Expand Down Expand Up @@ -212,7 +239,7 @@ genSystemCoreUsingGencore(struct OMRPortLibrary *portLibrary, char *filename)
*
* @param[out] coreFilePath caller allocated buffer to put preferred destination for core file.
*
* @note buffer is not modified if a preferred desitination was not found
* @note buffer is not modified if a preferred destination was not found
* @note buffer length is platform dependent, assumed to be EsMaxPath/MAX_PATH
*/
void
Expand All @@ -226,7 +253,7 @@ findOSPreferredCoreDir(struct OMRPortLibrary *portLibrary, char *coreFilePath)

getPEnvValue(portLibrary, CORE_PATH_ENV_STRING, buffer);

/* path via the chcore command takes precedence, if it was not set, check the path set via the syscorepath command*/
/* path via the chcore command takes precedence, if it was not set, check the path set via the syscorepath command */
if (buffer[0] == '\0') {
sysconfig(GET_COREPATH, buffer, MAXPATHLEN);
#if defined(DUMP_DBG)
Expand Down
5 changes: 4 additions & 1 deletion port/unix/omrosdump.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2019 IBM Corp. and others
* Copyright (c) 1991, 2022 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 @@ -238,6 +238,9 @@ omrdump_create(struct OMRPortLibrary *portLibrary, char *filename, char *dumpTyp
}

/* Apply suggested name */
#if defined(DUMP_DBG)
portLibrary->tty_err_printf(portLibrary, "Attempting to rename \"%s\" to \"%s\"\n", corepath, filename);
#endif /* defined(DUMP_DBG) */
if (rename(corepath, filename)) {
portLibrary->str_printf(portLibrary, filename, EsMaxPath, "cannot find core file: \"%s\". check \"ulimit -Hc\" is set high enough", strerror(errno));
return 1;
Expand Down

0 comments on commit dc315bf

Please sign in to comment.