diff --git a/src/util/session_dir.c b/src/util/session_dir.c index e3ad283f71..99e66515d4 100644 --- a/src/util/session_dir.c +++ b/src/util/session_dir.c @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include /* #include @@ -168,12 +171,12 @@ int ompi_session_dir(bool create, char *prefix, char *user, char *hostid, char * COMPLETE: if (create) { - if (proc) { + if (NULL != proc) { ompi_process_info.proc_session_dir = strdup(fulldirpath); fulldirpath = dirname(fulldirpath); } - if (job) { + if (NULL != job) { ompi_process_info.job_session_dir = strdup(fulldirpath); fulldirpath = dirname(fulldirpath); } @@ -209,8 +212,58 @@ int ompi_session_dir(bool create, char *prefix, char *user, char *hostid, char * int ompi_session_dir_finalize() { - /* BWB - fix me, fix me, fix me */ - printf("WARNING: session directory not removed - " - "function not implemented\n"); + if (OMPI_SUCCESS != ompi_clean_dir(ompi_process_info.proc_session_dir)) { + return OMPI_ERROR; /* should have been able to at least clear my own */ + } + + if (OMPI_SUCCESS != ompi_clean_dir(ompi_process_info.job_session_dir)) { + return OMPI_SUCCESS; /* need new error condition - could be okay not to clear */ + } + + if (OMPI_SUCCESS != ompi_clean_dir(ompi_process_info.universe_session_dir)) { + return OMPI_SUCCESS; + } + return OMPI_SUCCESS; } + +int +ompi_clean_dir(char *pathname) +{ + DIR *dp; + struct dirent *ep; + char *filenm; + + if (NULL != pathname) { /* protect against error */ + dp = opendir(pathname); + if (NULL != dp) { + while ((ep = readdir(dp))) { + if ((0 != strcmp(ep->d_name, ".")) && + (0 != strcmp(ep->d_name, "..")) && + (DT_DIR != ep->d_type)) { + filenm = ompi_os_path(true, pathname, ep->d_name, NULL); + if (!unlink(filenm)) { + if (ENOENT == errno) { /* file doesn't exist - race condition */ + /* ignore this */ + } else if (EBUSY == errno) { /* someone using it */ + /* left in for diag purposes - should print something */ + /* otherwise, normally just report error */ + } else { /* no idea what to do - punt */ + return OMPI_ERROR; + } + } + } + } + if (!rmdir(pathname)) { /* error */ + if (EEXIST == errno || ENOTEMPTY == errno) { /* not empty */ + } else if (ENOENT == errno || EBUSY == errno) { /* doesn't exist or busy - race condition */ + /* put in diagnostic message for now */ + } else { /* no idea */ + } + } + return OMPI_SUCCESS; + } + return OMPI_ERROR; + } + return OMPI_ERROR; +} diff --git a/src/util/session_dir.h b/src/util/session_dir.h index 7cf6387c57..768ced7bb0 100644 --- a/src/util/session_dir.h +++ b/src/util/session_dir.h @@ -129,3 +129,5 @@ int ompi_session_dir(bool create, char *prefix, char *user, char *hostid, * properly cleaned up. */ int ompi_session_dir_finalize(void); + +int ompi_clean_dir(char *pathname); diff --git a/test/util/Makefile.am b/test/util/Makefile.am index 50e9d602a1..5ee44a6518 100644 --- a/test/util/Makefile.am +++ b/test/util/Makefile.am @@ -17,79 +17,32 @@ noinst_PROGRAMS = \ ompi_numtostr_SOURCES = ompi_numtostr.c ompi_numtostr_LDADD = \ - $(top_builddir)/src/class/ompi_object.lo \ - $(top_builddir)/src/util/malloc.lo \ - $(top_builddir)/src/util/output.lo \ - $(top_builddir)/src/util/argv.lo \ - $(top_builddir)/src/util/strncpy.lo \ - $(top_builddir)/src/threads/mutex.lo \ - $(top_builddir)/src/threads/mutex_pthread.lo \ - $(top_builddir)/src/threads/mutex_spinlock.lo \ - $(top_builddir)/src/threads/mutex_spinwait.lo \ - $(top_builddir)/src/util/numtostr.lo \ + $(top_builddir)/src/libmpi.la \ $(top_builddir)/test/support/libsupport.la ompi_numtostr_DEPENDENCIES = $(ompi_numtostr_LDADD) ompi_argv_SOURCES = ompi_argv.c ompi_argv_LDADD = \ - $(top_builddir)/src/class/ompi_object.lo \ - $(top_builddir)/src/util/malloc.lo \ - $(top_builddir)/src/util/output.lo \ - $(top_builddir)/src/util/argv.lo \ - $(top_builddir)/src/util/strncpy.lo \ - $(top_builddir)/src/threads/mutex.lo \ - $(top_builddir)/src/threads/mutex_pthread.lo \ - $(top_builddir)/src/threads/mutex_spinlock.lo \ - $(top_builddir)/src/threads/mutex_spinwait.lo \ + $(top_builddir)/src/libmpi.la \ $(top_builddir)/test/support/libsupport.la ompi_argv_DEPENDENCIES = $(ompi_argv_LDADD) ompi_os_path_SOURCES = ompi_os_path.c ompi_os_path_LDADD = \ - $(top_builddir)/src/util/sys_info.lo \ - $(top_builddir)/src/class/ompi_object.lo \ - $(top_builddir)/src/util/malloc.lo \ - $(top_builddir)/src/util/output.lo \ - $(top_builddir)/src/util/argv.lo \ - $(top_builddir)/src/util/strncpy.lo \ - $(top_builddir)/src/threads/mutex.lo \ - $(top_builddir)/src/threads/mutex_pthread.lo \ - $(top_builddir)/src/threads/mutex_spinlock.lo \ - $(top_builddir)/src/threads/mutex_spinwait.lo \ - $(top_builddir)/src/util/os_path.lo \ + $(top_builddir)/src/libmpi.la \ $(top_builddir)/test/support/libsupport.la ompi_os_path_DEPENDENCIES = $(ompi_os_path_LDADD) ompi_sys_info_SOURCES = ompi_sys_info.c ompi_sys_info_LDADD = \ - $(top_builddir)/src/util/sys_info.lo \ - $(top_builddir)/src/class/ompi_object.lo \ - $(top_builddir)/src/util/malloc.lo \ - $(top_builddir)/src/util/output.lo \ - $(top_builddir)/src/util/argv.lo \ - $(top_builddir)/src/util/strncpy.lo \ - $(top_builddir)/src/threads/mutex.lo \ - $(top_builddir)/src/threads/mutex_pthread.lo \ - $(top_builddir)/src/threads/mutex_spinlock.lo \ - $(top_builddir)/src/threads/mutex_spinwait.lo \ + $(top_builddir)/src/libmpi.la \ $(top_builddir)/test/support/libsupport.la ompi_sys_info_DEPENDENCIES = $(ompi_sys_info_LDADD) ompi_os_create_dirpath_SOURCES = ompi_os_create_dirpath.c ompi_os_create_dirpath_LDADD = \ - $(top_builddir)/src/util/sys_info.lo \ - $(top_builddir)/src/class/ompi_object.lo \ - $(top_builddir)/src/util/malloc.lo \ - $(top_builddir)/src/util/output.lo \ - $(top_builddir)/src/util/argv.lo \ - $(top_builddir)/src/util/strncpy.lo \ - $(top_builddir)/src/threads/mutex.lo \ - $(top_builddir)/src/threads/mutex_pthread.lo \ - $(top_builddir)/src/threads/mutex_spinlock.lo \ - $(top_builddir)/src/threads/mutex_spinwait.lo \ - $(top_builddir)/src/util/os_path.lo \ - $(top_builddir)/src/util/os_create_dirpath.lo \ + $(top_builddir)/src/libmpi.la \ $(top_builddir)/test/support/libsupport.la ompi_os_create_dirpath_DEPENDENCIES = $(ompi_os_create_dirpath_LDADD) diff --git a/test/util/ompi_session_dir.c b/test/util/ompi_session_dir.c index f531dc6649..e492b4fe97 100644 --- a/test/util/ompi_session_dir.c +++ b/test/util/ompi_session_dir.c @@ -15,28 +15,9 @@ #include "util/sys_info.h" #include "util/os_path.h" #include "util/session_dir.h" +#include "util/proc_info.h" #include "support.h" -struct ompi_proc_info_t { - bool init; /**< Certifies that values have been filled. - * Certifies that the ompi_sys_info() function has been - * called at least once so fields have valid values - */ - char *universe_session_dir; /**< Location of universe temp dir. - * The session directory has the form - * , where the prefix - * can either be provided by the user via the - * --tmpdir command-line flag, the use of one of several - * environmental variables, or else a default location. - */ - - char *job_session_dir; /**< Session directory for job */ - - char *proc_session_dir; /**< Session directory for the process */ -}; -typedef struct ompi_proc_info_t ompi_proc_info_t; - -ompi_proc_info_t ompi_process_info; static bool test1(void); /* given prefix, both one that works and one that fails */ static bool test2(void); /* no prefix given, OMPI_PREFIX_ENV set, one good and one bad */ @@ -44,15 +25,24 @@ static bool test3(void); /* no prefix given, TMPDIR set, one good and one bad static bool test4(void); /* no prefix given, TMP set, one good and one bad */ static bool test5(void); /* no prefix given, HOME set, one good and one bad */ static bool test6(void); /* no prefix given, nothing set, one good and one bad */ +static bool test7(void); /* remove session directory tree */ +static FILE *test_out=NULL; int main(int argc, char* argv[]) { ompi_sys_info(); /* initialize system */ test_init("ompi_session_dir_t"); - + test_out = fopen( "test_session_dir_out", "w+" ); + if( test_out == NULL ) { + test_failure("test_session_dir couldn't open test file failed"); + test_finalize(); + exit(1); + } + + fprintf(test_out, "running test1\n"); if (test1()) { test_success(); } @@ -60,6 +50,7 @@ int main(int argc, char* argv[]) test_failure("ompi_session_dir_t test1 failed"); } + fprintf(test_out, "running test2\n"); if (test2()) { test_success(); } @@ -67,6 +58,7 @@ int main(int argc, char* argv[]) test_failure("ompi_session_dir_t test2 failed"); } + fprintf(test_out, "running test3\n"); if (test3()) { test_success(); } @@ -74,6 +66,7 @@ int main(int argc, char* argv[]) test_failure("ompi_session_dir_t test3 failed"); } + fprintf(test_out, "running test4\n"); if (test4()) { test_success(); } @@ -81,6 +74,7 @@ int main(int argc, char* argv[]) test_failure("ompi_session_dir_t test4 failed"); } + fprintf(test_out, "running test5\n"); if (test5()) { test_success(); } @@ -88,6 +82,7 @@ int main(int argc, char* argv[]) test_failure("ompi_session_dir_t test5 failed"); } + fprintf(test_out, "running test6\n"); if (test6()) { test_success(); } @@ -95,6 +90,15 @@ int main(int argc, char* argv[]) test_failure("ompi_session_dir_t test6 failed"); } + fprintf(test_out, "running test7\n"); + if (test7()) { + test_success(); + } + else { + test_failure("ompi_session_dir_t test6 failed"); + } + + fclose(test_out); test_finalize(); return 0; } @@ -257,3 +261,23 @@ static bool test6(void) return(true); } + +static bool test7(void) +{ + + /* create test proc session directory tree */ + if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, "localhost", NULL, "test-universe", "test-job", "test-proc")) { + return(false); + } + + fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n", + ompi_process_info.proc_session_dir, + ompi_process_info.job_session_dir, + ompi_process_info.universe_session_dir); + + if (OMPI_ERROR == ompi_session_dir_finalize()) { + return(false); + } + + return true; +}