diff --git a/src/util/os_path.c b/src/util/os_path.c index 5a15b51524..46395356bc 100644 --- a/src/util/os_path.c +++ b/src/util/os_path.c @@ -29,7 +29,8 @@ #include #include -#include "include/constants.h" +#include "include/orte_constants.h" +#include "util/sys_info.h" #include "util/os_path.h" #include "util/sys_info.h" @@ -91,7 +92,9 @@ char *orte_os_path(bool relative, ...) } while (NULL != (element=va_arg(ap1, char*))) { - strcat(path, orte_system_info.path_sep); + if (orte_system_info.path_sep[0] != element[0]) { + strcat(path, orte_system_info.path_sep); + } strcat(path, element); } diff --git a/src/util/session_dir.c b/src/util/session_dir.c index 2fb59ef278..0c96d5657b 100644 --- a/src/util/session_dir.c +++ b/src/util/session_dir.c @@ -377,58 +377,66 @@ int orte_session_dir(bool create, char *prfx, char *usr, char *hostid, int orte_session_dir_finalize() { + char *tmp; + + /* need to setup the top_session_dir with the prefix */ + tmp = strdup(orte_os_path(false, + orte_process_info.tmpdir_base, + orte_process_info.top_session_dir, NULL)); + orte_dir_empty(orte_process_info.proc_session_dir); orte_dir_empty(orte_process_info.job_session_dir); orte_dir_empty(orte_process_info.universe_session_dir); - orte_dir_empty(orte_process_info.top_session_dir); + orte_dir_empty(tmp); if (orte_is_empty(orte_process_info.proc_session_dir)) { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: found proc session dir empty - deleting"); - } - rmdir(orte_process_info.proc_session_dir); + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: found proc session dir empty - deleting"); + } + rmdir(orte_process_info.proc_session_dir); } else { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: proc session dir not empty - leaving"); - } - return OMPI_SUCCESS; + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: proc session dir not empty - leaving"); + } + return OMPI_SUCCESS; } if (orte_is_empty(orte_process_info.job_session_dir)) { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: found job session dir empty - deleting"); - } - rmdir(orte_process_info.job_session_dir); + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: found job session dir empty - deleting"); + } + rmdir(orte_process_info.job_session_dir); } else { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: job session dir not empty - leaving"); - } - return OMPI_SUCCESS; + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: job session dir not empty - leaving"); + } + return OMPI_SUCCESS; } if (orte_is_empty(orte_process_info.universe_session_dir)) { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: found univ session dir empty - deleting"); - } - rmdir(orte_process_info.universe_session_dir); + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: found univ session dir empty - deleting"); + } + rmdir(orte_process_info.universe_session_dir); } else { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: univ session dir not empty - leaving"); - } - return OMPI_SUCCESS; + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: univ session dir not empty - leaving"); + } + return OMPI_SUCCESS; } - if (orte_is_empty(orte_process_info.top_session_dir)) { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: found top session dir empty - deleting"); - } - rmdir(orte_process_info.top_session_dir); + if (orte_is_empty(tmp)) { + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: found top session dir empty - deleting"); + } + rmdir(tmp); } else { - if (orte_debug_flag) { - ompi_output(0, "sess_dir_finalize: top session dir not empty - leaving"); - } + if (orte_debug_flag) { + ompi_output(0, "sess_dir_finalize: top session dir not empty - leaving"); + } } + free(tmp); return OMPI_SUCCESS; } @@ -524,22 +532,21 @@ static bool orte_is_empty(char *pathname) #ifndef WIN32 DIR *dp; struct dirent *ep; - 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, ".."))) { - return false; - } - } - closedir(dp); - return true; - } - return false; + dp = opendir(pathname); + if (NULL != dp) { + while ((ep = readdir(dp))) { + if ((0 != strcmp(ep->d_name, ".")) && + (0 != strcmp(ep->d_name, ".."))) { + return false; + } + } + closedir(dp); + return true; + } + return false; } - return false; + return true; #else char search_path[MAX_PATH]; HANDLE file; diff --git a/test/runtime/ompi_session_dir.c b/test/runtime/ompi_session_dir.c deleted file mode 100644 index 35ccb2b5b8..0000000000 --- a/test/runtime/ompi_session_dir.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Trustees of Indiana University. - * All rights reserved. - * Copyright (c) 2004-2005 The Trustees of the University of Tennessee. - * All rights reserved. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -#include "ompi_config.h" -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_LIBGEN_H -#include -#endif -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#include - -#include "support.h" -#include "include/constants.h" -#include "util/sys_info.h" -#include "util/os_path.h" -#include "util/session_dir.h" - -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 */ -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 */ - - -int main(int argc, char* argv[]) -{ - ompi_sys_info(); /* initialize system */ - - /* Perform overall test initialization */ - test_init("ompi_bitmap_t"); - - if (test1()) { - test_success(); - } - else { - test_failure("ompi_session_dir_t test1 failed"); - } - - if (test2()) { - test_success(); - } - else { - test_failure("ompi_session_dir_t test2 failed"); - } - - if (test3()) { - test_success(); - } - else { - test_failure("ompi_session_dir_t test3 failed"); - } - - if (test4()) { - test_success(); - } - else { - test_failure("ompi_session_dir_t test4 failed"); - } - - if (test5()) { - test_success(); - } - else { - test_failure("ompi_session_dir_t test5 failed"); - } - - if (test6()) { - test_success(); - } - else { - test_failure("ompi_session_dir_t test6 failed"); - } - - test_finalize(); - return 0; -} - - -static bool test1(void) -{ - /* Test proper action when given a prefix */ - - char *prefix, *tmp, *tmp2; - - /* see if we can create a specified path */ - - prefix = ompi_os_path(false, "tmp", NULL); - if (OMPI_ERROR == ompi_session_dir(true, prefix, "test-universe", - ompi_system_info.user, NULL, NULL, NULL, NULL)) { - free(prefix); - return(false); - } - /* see if it can access an existing path */ - - if (OMPI_ERROR == ompi_session_dir(false, prefix, "test-universe", - ompi_system_info.user, NULL, NULL, NULL, NULL)) { - free(prefix); - return(false); - } - - /* Currently, to remove the session, we need to call - * ompi_session_dir_finalize. - * - * NOTE: this will have to change at a future revision, since the - * plan is to leave the session dir around. We will have to - * call a TBD function that will remove the session. - */ - ompi_session_dir_finalize (); - free(prefix); - free(tmp); - - /* check what happens when given prefix that won't allow access */ - tmp2 = ompi_os_path(false, "test", NULL); /* assume we don't have root privileges */ - if (OMPI_SUCCESS == ompi_session_dir(true, tmp2, "test-universe", - ompi_system_info.user, NULL, NULL, NULL, NULL)) { - printf("created temp directory in %s - shouldn't have been able to do so\n", tmp2); - ompi_session_dir_finalize(); - free(tmp); - free(tmp2); - return(false); - } - - return true; -} - - -static bool test2(void) -{ - char *tmp; - - /* use the OMPI_PREFIX_ENV variable */ - - setenv("OMPI_PREFIX_ENV", "/tmp/trythis", 1); - - if (OMPI_ERROR == ompi_session_dir(true, NULL, "test-universe", - ompi_system_info.user, NULL, NULL, NULL, NULL)) { - unsetenv("OMPI_PREFIX_ENV"); - return(false); - } - - ompi_session_dir_finalize (); - free(tmp); - - unsetenv("OMPI_PREFIX_ENV"); - - return(true); - -} - - -static bool test3(void) -{ - /* use the TMPDIR enviro variable */ - char *tmp; - - setenv("TMPDIR", "/tmp/trythis", 1); - - if (OMPI_ERROR == ompi_session_dir(true, NULL, "test-universe", - ompi_system_info.user, NULL, NULL, NULL, NULL)) { - unsetenv("TMPDIR"); - return(false); - } - - ompi_session_dir_finalize (); - free(tmp); - - unsetenv("TMPDIR"); - - return(true); -} - - -static bool test4(void) -{ - /* use the TMP enviro variable */ - char *tmp; - - setenv("TMP", "/tmp/trythis", 1); - - if (OMPI_ERROR == ompi_session_dir(true, NULL, "test-universe", - ompi_system_info.user, NULL, NULL, NULL, NULL)) { - unsetenv("TMP"); - return(false); - } - - ompi_session_dir_finalize (); - free(tmp); - - unsetenv("TMP"); - - return(true); -} - - -static bool test5(void) -{ - /* use the HOME enviro variable */ - char *tmp; - - setenv("HOME", "/tmp/trythis", 1); - - if (OMPI_ERROR == ompi_session_dir(true, NULL, "test-universe", ompi_system_info.user, NULL, NULL, NULL, NULL)) { - unsetenv("HOME"); - return(false); - } - - ompi_session_dir_finalize (); - free(tmp); - - unsetenv("HOME"); - - return(true); -} - - -static bool test6(void) -{ - - /* no enviro variables set, no prefix given - * Program should turn to default of /tmp (where "/" is whatever - * top-level directory is appropriate for given system) - */ - if (OMPI_ERROR == ompi_session_dir(true, NULL, "test-universe", - ompi_system_info.user, NULL, NULL, NULL, NULL)) { - return(false); - } - - ompi_session_dir_finalize(); - return(true); -} diff --git a/test/util/orte_session_dir.c b/test/util/orte_session_dir.c index b6923087bd..1c8a4e5e2f 100644 --- a/test/util/orte_session_dir.c +++ b/test/util/orte_session_dir.c @@ -35,6 +35,7 @@ #include "util/os_create_dirpath.h" #include "util/session_dir.h" #include "util/proc_info.h" +#include "runtime/runtime.h" #include "support.h" @@ -54,7 +55,7 @@ static FILE *test_out=NULL; int main(int argc, char* argv[]) { orte_sys_info(); /* initialize system */ - + test_init("orte_session_dir_t"); test_out = fopen( "test_session_dir_out", "w+" ); if( test_out == NULL ) { @@ -140,7 +141,7 @@ static bool test1(void) { /* Test proper action when given a prefix */ - char *prefix, *tmp; + char *prefix; /* see if we can create a specified path */ @@ -160,12 +161,9 @@ static bool test1(void) return(false); } - rmdir(orte_process_info.universe_session_dir); - tmp = strdup(dirname(orte_process_info.universe_session_dir)); - rmdir(tmp); + orte_session_dir_finalize(); free(orte_process_info.universe_session_dir); free(prefix); - free(tmp); return true; } @@ -173,8 +171,6 @@ static bool test1(void) static bool test2(void) { - char *tmp; - clear_proc_info(); /* use the OMPI_PREFIX_ENV variable */ @@ -186,10 +182,7 @@ static bool test2(void) return(false); } - rmdir(orte_process_info.universe_session_dir); - tmp = strdup(dirname(orte_process_info.universe_session_dir)); - rmdir(tmp); - free(tmp); + orte_session_dir_finalize(); unsetenv("OMPI_PREFIX_ENV"); @@ -201,8 +194,6 @@ static bool test2(void) static bool test3(void) { /* use the TMPDIR enviro variable */ - char *tmp; - clear_proc_info(); setenv("TMPDIR", "/tmp/trythis", 1); @@ -212,10 +203,7 @@ static bool test3(void) return(false); } - rmdir(orte_process_info.universe_session_dir); - tmp = strdup(dirname(orte_process_info.universe_session_dir)); - rmdir(tmp); - free(tmp); + orte_session_dir_finalize(); unsetenv("TMPDIR"); @@ -226,7 +214,6 @@ static bool test3(void) static bool test4(void) { /* use the TMP enviro variable */ - char *tmp; clear_proc_info(); @@ -237,10 +224,7 @@ static bool test4(void) return(false); } - rmdir(orte_process_info.universe_session_dir); - tmp = strdup(dirname(orte_process_info.universe_session_dir)); - rmdir(tmp); - free(tmp); + orte_session_dir_finalize(); unsetenv("TMP"); @@ -251,7 +235,6 @@ static bool test4(void) static bool test5(void) { /* use the HOME enviro variable */ - char *tmp; clear_proc_info(); @@ -262,10 +245,7 @@ static bool test5(void) return(false); } - rmdir(orte_process_info.universe_session_dir); - tmp = strdup(dirname(orte_process_info.universe_session_dir)); - rmdir(tmp); - free(tmp); + orte_session_dir_finalize(); unsetenv("HOME"); @@ -275,7 +255,6 @@ static bool test5(void) static bool test6(void) { - char *tmp; clear_proc_info(); @@ -287,17 +266,16 @@ static bool test6(void) return(false); } - rmdir(orte_process_info.universe_session_dir); - tmp = strdup(dirname(orte_process_info.universe_session_dir)); - rmdir(tmp); + orte_session_dir_finalize(); return(true); } static bool test7(void) { - char *filenm; + char *filenm[5]; FILE *fp; + int i; clear_proc_info(); @@ -313,18 +291,18 @@ static bool test7(void) /* create some files */ - filenm = orte_os_path(false, orte_process_info.proc_session_dir, "dum1", NULL); - fp = fopen(filenm, "w"); + filenm[0] = orte_os_path(false, orte_process_info.proc_session_dir, "dum1", NULL); + fp = fopen(filenm[0], "w"); fprintf(fp, "ss"); fclose(fp); - filenm = orte_os_path(false, orte_process_info.job_session_dir, "dum2", NULL); - fp = fopen(filenm, "w"); + filenm[1] = orte_os_path(false, orte_process_info.job_session_dir, "dum2", NULL); + fp = fopen(filenm[1], "w"); fprintf(fp, "ss"); fclose(fp); - filenm = orte_os_path(false, orte_process_info.universe_session_dir, "dum3", NULL); - fp = fopen(filenm, "w"); + filenm[2] = orte_os_path(false, orte_process_info.universe_session_dir, "dum3", NULL); + fp = fopen(filenm[2], "w"); fprintf(fp, "ss"); fclose(fp); @@ -332,18 +310,22 @@ static bool test7(void) return(false); } + for (i=0; i < 3; i++) unlink(filenm[i]); + orte_session_dir_finalize(); + return true; } static bool test8(void) { - char *filenm; + char *filenm[5]; FILE *fp; + int i; clear_proc_info(); /* create test proc session directory tree */ - if (OMPI_ERROR == orte_session_dir(true, NULL, orte_system_info.user, "localhost", NULL, "test-universe2", "test-job", "test-proc")) { + if (OMPI_ERROR == orte_session_dir(true, NULL, orte_system_info.user, "localhost", NULL, "test-universe2", "test-job2", "test-proc2")) { return(false); } @@ -354,29 +336,29 @@ static bool test8(void) /* create some files */ - filenm = orte_os_path(false, orte_process_info.proc_session_dir, "dum1", NULL); - fp = fopen(filenm, "w"); + filenm[0] = orte_os_path(false, orte_process_info.proc_session_dir, "dum1", NULL); + fp = fopen(filenm[0], "w"); fprintf(fp, "ss"); fclose(fp); - filenm = orte_os_path(false, orte_process_info.job_session_dir, "dum2", NULL); - fp = fopen(filenm, "w"); + filenm[1] = orte_os_path(false, orte_process_info.job_session_dir, "dum2", NULL); + fp = fopen(filenm[1], "w"); fprintf(fp, "ss"); fclose(fp); - filenm = orte_os_path(false, orte_process_info.universe_session_dir, "dum3", NULL); - fp = fopen(filenm, "w"); + filenm[2] = orte_os_path(false, orte_process_info.universe_session_dir, "dum3", NULL); + fp = fopen(filenm[2], "w"); fprintf(fp, "ss"); fclose(fp); - filenm = orte_os_path( false, orte_process_info.job_session_dir, "dir1", NULL); - orte_os_create_dirpath(filenm, 0777); - if (OMPI_ERROR == orte_session_dir_finalize()) { - return(false); + return(false); } + for (i=0; i < 3; i++) unlink(filenm[i]); + orte_session_dir_finalize(); + return true; }