1
1

Fixes provided by Ralph to help cleanup of the session directory,

especially upon abnormal termination of a process.  Not yet integrated
into the fork pls; pending more discussion with other developers.

This commit was SVN r5326.
Этот коммит содержится в:
Jeff Squyres 2005-04-14 01:04:26 +00:00
родитель 1fac78adb4
Коммит 2be1a1a2f3
4 изменённых файлов: 78 добавлений и 48 удалений

Просмотреть файл

@ -59,7 +59,7 @@ int orte_finalize(void)
ompi_event_fini();
#ifndef WIN32
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
#endif
/* clean out the global structures */

Просмотреть файл

@ -13,9 +13,6 @@
*
* $HEADER$
*
* $Id: tmpdir.c $
*
* Function: -
*/
#include "orte_config.h"
@ -45,28 +42,6 @@
#include <dirent.h>
#endif
/*
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
#include <orte_debug.h>
#include <orte_internal.h>
#include <terror.h>
#include <typical.h>
#include <etc_misc.h>
*/
#include "include/constants.h"
#include "util/univ_info.h"
@ -76,6 +51,7 @@
#include "util/os_path.h"
#include "util/os_create_dirpath.h"
#include "mca/errmgr/errmgr.h"
#include "runtime/runtime.h"
#include "util/session_dir.h"
@ -375,42 +351,77 @@ int orte_session_dir(bool create, char *prfx, char *usr, char *hostid,
int
orte_session_dir_finalize()
orte_session_dir_finalize(orte_process_name_t *proc)
{
int rc;
char *tmp;
char *job, *job_session_dir, *vpid, *proc_session_dir;
/* 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);
/* define the proc and job session directories for this process */
if (ORTE_SUCCESS != (rc = orte_ns.get_jobid_string(&job, proc))) {
ORTE_ERROR_LOG(rc);
free(tmp);
return rc;
}
if (ORTE_SUCCESS != (rc = orte_ns.get_vpid_string(&vpid, proc))) {
ORTE_ERROR_LOG(rc);
free(tmp);
free(job);
return rc;
}
if (0 > asprintf(&job_session_dir, "%s%s%s",
orte_process_info.universe_session_dir,
orte_system_info.path_sep, job)) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
free(tmp);
free(job);
free(vpid);
return ORTE_ERR_OUT_OF_RESOURCE;
}
if (0 > asprintf(&proc_session_dir, "%s%s%s",
job_session_dir,
orte_system_info.path_sep, vpid)) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
free(tmp);
free(job);
free(vpid);
free(job_session_dir);
return ORTE_ERR_OUT_OF_RESOURCE;
}
orte_dir_empty(proc_session_dir);
orte_dir_empty(job_session_dir);
orte_dir_empty(orte_process_info.universe_session_dir);
orte_dir_empty(tmp);
if (orte_is_empty(orte_process_info.proc_session_dir)) {
if (orte_is_empty(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);
rmdir(proc_session_dir);
} else {
if (orte_debug_flag) {
ompi_output(0, "sess_dir_finalize: proc session dir not empty - leaving");
}
return OMPI_SUCCESS;
goto CLEANUP;
}
if (orte_is_empty(orte_process_info.job_session_dir)) {
if (orte_is_empty(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);
rmdir(job_session_dir);
} else {
if (orte_debug_flag) {
ompi_output(0, "sess_dir_finalize: job session dir not empty - leaving");
}
return OMPI_SUCCESS;
goto CLEANUP;
}
if (orte_is_empty(orte_process_info.universe_session_dir)) {
@ -422,7 +433,7 @@ orte_session_dir_finalize()
if (orte_debug_flag) {
ompi_output(0, "sess_dir_finalize: univ session dir not empty - leaving");
}
return OMPI_SUCCESS;
goto CLEANUP;
}
if (orte_is_empty(tmp)) {
@ -436,7 +447,12 @@ orte_session_dir_finalize()
}
}
CLEANUP:
free(tmp);
free(job);
free(vpid);
free(job_session_dir);
free(proc_session_dir);
return OMPI_SUCCESS;
}

Просмотреть файл

@ -84,6 +84,8 @@
*/
#include "orte_config.h"
#include "mca/ns/ns_types.h"
/** @param create A boolean variable that indicates whether or not to
* create the specified directory. If set to "false",
* the function only checks to see if an existing
@ -141,4 +143,4 @@ OMPI_DECLSPEC int orte_session_dir(bool create, char *prefix, char *user, char *
* @retval OMPI_ERROR If something prevents the tree from being
* properly cleaned up.
*/
OMPI_DECLSPEC int orte_session_dir_finalize(void);
OMPI_DECLSPEC int orte_session_dir_finalize(orte_process_name_t *proc);

Просмотреть файл

@ -29,7 +29,9 @@
#endif
#include <sys/stat.h>
#include "include/constants.h"
#include "include/orte_constants.h"
#include "mca/ns/ns_types.h"
#include "util/proc_info.h"
#include "util/sys_info.h"
#include "util/os_path.h"
#include "util/os_create_dirpath.h"
@ -55,6 +57,11 @@ static FILE *test_out=NULL;
int main(int argc, char* argv[])
{
orte_sys_info(); /* initialize system */
orte_proc_info(); /* initialize proc info structure */
orte_process_info.my_name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t));
orte_process_info.my_name->cellid = 0;
orte_process_info.my_name->jobid = 0;
orte_process_info.my_name->vpid = 0;
test_init("orte_session_dir_t");
test_out = fopen( "test_session_dir_out", "w+" );
@ -132,6 +139,11 @@ int main(int argc, char* argv[])
fprintf(test_out, "completed all tests\n");
fclose(test_out);
/* clean up */
orte_sys_info_finalize();
orte_proc_info_finalize();
test_finalize();
return 0;
}
@ -161,7 +173,7 @@ static bool test1(void)
return(false);
}
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
free(orte_process_info.universe_session_dir);
free(prefix);
@ -182,7 +194,7 @@ static bool test2(void)
return(false);
}
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
unsetenv("OMPI_PREFIX_ENV");
@ -203,7 +215,7 @@ static bool test3(void)
return(false);
}
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
unsetenv("TMPDIR");
@ -224,7 +236,7 @@ static bool test4(void)
return(false);
}
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
unsetenv("TMP");
@ -245,7 +257,7 @@ static bool test5(void)
return(false);
}
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
unsetenv("HOME");
@ -266,7 +278,7 @@ static bool test6(void)
return(false);
}
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
return(true);
}
@ -306,12 +318,12 @@ static bool test7(void)
fprintf(fp, "ss");
fclose(fp);
if (OMPI_ERROR == orte_session_dir_finalize()) {
if (OMPI_ERROR == orte_session_dir_finalize(orte_process_info.my_name)) {
return(false);
}
for (i=0; i < 3; i++) unlink(filenm[i]);
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
return true;
}
@ -352,12 +364,12 @@ static bool test8(void)
fclose(fp);
if (OMPI_ERROR == orte_session_dir_finalize()) {
if (OMPI_ERROR == orte_session_dir_finalize(orte_process_info.my_name)) {
return(false);
}
for (i=0; i < 3; i++) unlink(filenm[i]);
orte_session_dir_finalize();
orte_session_dir_finalize(orte_process_info.my_name);
return true;
}