From f3256a1140f086d1a1b67c1133eded19b91ff147 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Tue, 14 Sep 2004 03:59:17 +0000 Subject: [PATCH] Discovered a very, very interesting bug, courtesy of Jeff point out some unexpected behavior under Linux. It turns out that the Linux "dirname" function has a bug in it - namely, it modifies the argument passed to it, in violation of its documentation. This was apparently fixed in the Mac library - it definitely does NOT modify its argument on the Mac. After spending hours tracking this down, I finally did manage to isolate it to the dirname function. I have installed a "fix" for the problem (using an intermediate temporary copy of the string being passed to the function) that solves the problem without messing us up on the Mac. Hopefully, we won't find too many more such "cute" errors! This commit was SVN r2643. --- src/util/os_create_dirpath.c | 6 ++++-- src/util/session_dir.c | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/util/os_create_dirpath.c b/src/util/os_create_dirpath.c index 5a7236ee5d..4c5aee643f 100644 --- a/src/util/os_create_dirpath.c +++ b/src/util/os_create_dirpath.c @@ -16,7 +16,7 @@ int ompi_os_create_dirpath(const char *path, const mode_t mode) { - char *pth, *bottom_up; + char *pth, *bottom_up, *tmp; struct stat buf; if (NULL == path) { /* protect ourselves from errors */ @@ -58,7 +58,9 @@ int ompi_os_create_dirpath(const char *path, const mode_t mode) while (strcmp(pth, ".") != 0 && stat(pth, &buf) != 0) { /* see if directory exists, or if we've reached the top */ strcat(bottom_up, basename(pth)); /* doesn't exist yet, so save this name */ strcat(bottom_up, ompi_system_info.path_sep); - strcpy(pth, dirname(pth)); /* "pop" the directory tree */ + tmp = strdup(pth); + strcpy(pth, dirname(tmp)); /* "pop" the directory tree */ + free(tmp); } /* okay, ready to build from the top down */ diff --git a/src/util/session_dir.c b/src/util/session_dir.c index a72eaed91c..a948a481d3 100644 --- a/src/util/session_dir.c +++ b/src/util/session_dir.c @@ -77,7 +77,7 @@ int ompi_session_dir(bool create, char *prfx, char *usr, char *hostid, { char *fulldirpath=NULL, *tmp=NULL, *hostname=NULL, *batchname=NULL; char *sessions=NULL, *frontend=NULL, *user=NULL, *universe=NULL; - char *prefix=NULL; + char *prefix=NULL, *sav=NULL; int return_code; /* ensure that system info is set */ @@ -222,14 +222,18 @@ int ompi_session_dir(bool create, char *prfx, char *usr, char *hostid, if (NULL == ompi_process_info.proc_session_dir && NULL != proc) { ompi_process_info.proc_session_dir = strdup(fulldirpath); + sav = strdup(fulldirpath); free(fulldirpath); - fulldirpath = strdup(dirname(ompi_process_info.proc_session_dir)); + fulldirpath = strdup(dirname(sav)); + free(sav); } if (NULL == ompi_process_info.job_session_dir && NULL != job) { ompi_process_info.job_session_dir = strdup(fulldirpath); + sav = strdup(fulldirpath); free(fulldirpath); - fulldirpath = strdup(dirname(ompi_process_info.job_session_dir)); + fulldirpath = strdup(dirname(sav)); + free(sav); } if (NULL == ompi_process_info.universe_session_dir) {