2004-10-15 20:31:54 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* 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.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-10-15 20:31:54 +04:00
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
* $Id: tmpdir.c $
|
|
|
|
*
|
|
|
|
* Function: -
|
|
|
|
*/
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "orte_config.h"
|
2004-10-15 20:31:54 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_PWD_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <pwd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifdef HAVE_LIBGEN_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <libgen.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <sys/param.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <sys/stat.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <errno.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_DIRENT_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <dirent.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
/*
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <sys/socket.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <errno.h>
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifdef HAVE_DIRENT_H
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <dirent.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
#include <orte_debug.h>
|
|
|
|
#include <orte_internal.h>
|
2004-10-15 20:31:54 +04:00
|
|
|
#include <terror.h>
|
|
|
|
#include <typical.h>
|
|
|
|
#include <etc_misc.h>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include/constants.h"
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "util/univ_info.h"
|
2004-10-15 20:31:54 +04:00
|
|
|
#include "util/sys_info.h"
|
|
|
|
#include "util/proc_info.h"
|
|
|
|
#include "util/output.h"
|
|
|
|
#include "util/os_path.h"
|
|
|
|
#include "util/os_create_dirpath.h"
|
|
|
|
|
|
|
|
#include "runtime/runtime.h"
|
|
|
|
|
|
|
|
#include "util/session_dir.h"
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
static int orte_check_dir(bool create, char *directory);
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
static void orte_dir_empty(char *pathname);
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
static bool orte_is_empty(char *pathname);
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-01-25 01:51:15 +03:00
|
|
|
#ifdef WIN32
|
2005-01-20 03:03:23 +03:00
|
|
|
#define OMPI_DEFAULT_TMPDIR "C:\\TEMP"
|
2005-01-25 01:51:15 +03:00
|
|
|
#else
|
|
|
|
#define OMPI_DEFAULT_TMPDIR "/tmp"
|
|
|
|
#endif
|
2004-10-22 20:06:05 +04:00
|
|
|
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
static int orte_check_dir(bool create, char *directory)
|
2004-10-15 20:31:54 +04:00
|
|
|
{
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
2004-10-15 20:31:54 +04:00
|
|
|
struct stat buf;
|
|
|
|
mode_t my_mode = S_IRWXU; /* at the least, I need to be able to do anything */
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
|
|
|
struct __stat64 buf;
|
|
|
|
mode_t my_mode = _S_IREAD | _S_IWRITE | _S_IEXEC;
|
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
2004-10-15 20:31:54 +04:00
|
|
|
if (0 == stat(directory, &buf)) { /* exists - check access */
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
|
|
|
if (0 == _stat64(directory, &buf)) { /* exist -- check */
|
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
if ((buf.st_mode & my_mode) == my_mode) { /* okay, I can work here */
|
|
|
|
return(OMPI_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (create) {
|
2005-03-14 23:57:21 +03:00
|
|
|
return(orte_os_create_dirpath(directory, my_mode)); /* try to create it with proper mode */
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
return(OMPI_ERROR); /* couldn't find it, or don't have access rights, and not asked to create it */
|
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
int orte_session_dir(bool create, char *prfx, char *usr, char *hostid,
|
2004-10-15 20:31:54 +04:00
|
|
|
char *batchid, char *univ, char *job, char *proc)
|
|
|
|
{
|
|
|
|
char *fulldirpath=NULL, *tmp=NULL, *hostname=NULL, *batchname=NULL;
|
|
|
|
char *sessions=NULL, *frontend=NULL, *user=NULL, *universe=NULL;
|
|
|
|
char *prefix=NULL, *sav=NULL;
|
|
|
|
int return_code;
|
|
|
|
|
|
|
|
/* ensure that system info is set */
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_sys_info();
|
2004-10-15 20:31:54 +04:00
|
|
|
|
|
|
|
if (NULL == usr) { /* check if user set elsewhere */
|
2005-03-19 02:58:36 +03:00
|
|
|
if (NULL == orte_system_info.user) { /* error condition */
|
|
|
|
return OMPI_ERROR;
|
|
|
|
} else {
|
|
|
|
user = strdup(orte_system_info.user);
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-19 02:58:36 +03:00
|
|
|
user = strdup(usr);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == univ) { /* see if universe set elsewhere */
|
2005-03-19 02:58:36 +03:00
|
|
|
if (NULL == orte_universe_info.name) { /* error condition */
|
|
|
|
return OMPI_ERROR;
|
|
|
|
} else {
|
|
|
|
universe = strdup(orte_universe_info.name);
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-19 02:58:36 +03:00
|
|
|
universe = strdup(univ);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == job && NULL != proc) { /* can't give a proc without a job */
|
2005-03-19 02:58:36 +03:00
|
|
|
return OMPI_ERROR;
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == hostid) { /* check if hostname set elsewhere */
|
2005-03-19 02:58:36 +03:00
|
|
|
if (NULL == orte_system_info.nodename) { /* don't have a hostname anywhere - error */
|
|
|
|
return_code = OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
} else {
|
|
|
|
hostname = strdup(orte_system_info.nodename);
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-19 02:58:36 +03:00
|
|
|
hostname = strdup(hostid);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == batchid) {
|
2005-03-19 02:58:36 +03:00
|
|
|
batchname = strdup("0");
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-19 02:58:36 +03:00
|
|
|
batchname = batchid;
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL == orte_process_info.top_session_dir) {
|
2005-03-19 02:58:36 +03:00
|
|
|
if (0 > asprintf(&frontend, "openmpi-sessions-%s@%s_%s", user, hostname, batchname)) {
|
|
|
|
return_code = OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-19 02:58:36 +03:00
|
|
|
frontend = strdup(orte_process_info.top_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL != proc) {
|
2005-03-19 02:58:36 +03:00
|
|
|
if (0 > asprintf(&sessions, "%s%s%s%s%s%s%s", frontend,
|
|
|
|
orte_system_info.path_sep, universe,
|
|
|
|
orte_system_info.path_sep, job,
|
|
|
|
orte_system_info.path_sep, proc)) {
|
|
|
|
return_code = OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
} else if (NULL != job) {
|
2005-03-19 02:58:36 +03:00
|
|
|
if (0 > asprintf(&sessions, "%s%s%s%s%s", frontend,
|
|
|
|
orte_system_info.path_sep, universe,
|
|
|
|
orte_system_info.path_sep, job)) {
|
|
|
|
return_code = OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-19 02:58:36 +03:00
|
|
|
if (0 > asprintf(&sessions, "%s%s%s", frontend, orte_system_info.path_sep, universe)) {
|
|
|
|
return_code = OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL != prefix) { /* if a prefix is specified, start looking here */
|
2005-03-19 02:58:36 +03:00
|
|
|
tmp = strdup(prefix);
|
|
|
|
fulldirpath = strdup(orte_os_path(false, tmp, sessions, NULL)); /* make sure it's an absolute pathname */
|
|
|
|
if (OMPI_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = OMPI_SUCCESS;
|
|
|
|
goto COMPLETE;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
2005-03-19 02:58:36 +03:00
|
|
|
|
|
|
|
/* didn't find it, so first clear fulldirpath and tmp */
|
|
|
|
if (NULL != fulldirpath) {
|
|
|
|
free(fulldirpath); fulldirpath = NULL;
|
|
|
|
}
|
|
|
|
if (NULL != tmp) {
|
|
|
|
free(tmp); tmp = NULL;
|
|
|
|
}
|
|
|
|
|
2004-10-15 20:31:54 +04:00
|
|
|
/* no prefix was specified, so check other options in order */
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL != orte_process_info.tmpdir_base) { /* stored value previously */
|
2005-03-19 02:58:36 +03:00
|
|
|
tmp = strdup(orte_process_info.tmpdir_base);
|
|
|
|
fulldirpath = strdup(orte_os_path(false, tmp, sessions, NULL));
|
|
|
|
if (OMPI_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = OMPI_SUCCESS;
|
|
|
|
goto COMPLETE;
|
|
|
|
}
|
|
|
|
free(tmp); tmp = NULL;
|
|
|
|
free(fulldirpath); fulldirpath = NULL;
|
2004-10-15 20:31:54 +04:00
|
|
|
} else if (NULL != getenv("OMPI_PREFIX_ENV")) { /* we have prefix enviro var - try that next */
|
2005-03-19 02:58:36 +03:00
|
|
|
tmp = strdup(getenv("OMPI_PREFIX_ENV"));
|
|
|
|
fulldirpath = strdup(orte_os_path(false, tmp, sessions, NULL));
|
|
|
|
if (OMPI_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = OMPI_SUCCESS;
|
|
|
|
goto COMPLETE;
|
|
|
|
}
|
|
|
|
free(tmp); tmp = NULL;
|
|
|
|
free(fulldirpath); fulldirpath = NULL;
|
2004-10-15 20:31:54 +04:00
|
|
|
} else if (NULL != getenv("TMPDIR")) {
|
2005-03-19 02:58:36 +03:00
|
|
|
tmp = strdup(getenv("TMPDIR"));
|
|
|
|
fulldirpath = strdup(orte_os_path(false, tmp, sessions, NULL));
|
|
|
|
if (OMPI_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = OMPI_SUCCESS;
|
|
|
|
goto COMPLETE;
|
|
|
|
}
|
|
|
|
free(tmp); tmp = NULL;
|
|
|
|
free(fulldirpath); fulldirpath = NULL;
|
2004-10-15 20:31:54 +04:00
|
|
|
} else if (NULL != getenv("TMP")) {
|
2005-03-19 02:58:36 +03:00
|
|
|
tmp = strdup(getenv("TMP"));
|
|
|
|
fulldirpath = strdup(orte_os_path(false, tmp, sessions, NULL));
|
|
|
|
if (OMPI_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = OMPI_SUCCESS;
|
|
|
|
goto COMPLETE;
|
|
|
|
}
|
|
|
|
free(tmp); tmp = NULL;
|
|
|
|
free(fulldirpath); fulldirpath = NULL;
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-19 02:58:36 +03:00
|
|
|
tmp = strdup(OMPI_DEFAULT_TMPDIR);
|
|
|
|
fulldirpath = strdup(orte_os_path(false, tmp, sessions, NULL));
|
|
|
|
if (OMPI_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = OMPI_SUCCESS;
|
|
|
|
goto COMPLETE;
|
|
|
|
}
|
|
|
|
free(tmp); tmp = NULL;
|
|
|
|
free(fulldirpath); fulldirpath = NULL;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-03-19 02:58:36 +03:00
|
|
|
/* couldn't find anything - return error */
|
2004-10-15 20:31:54 +04:00
|
|
|
return_code = OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
2005-03-19 02:58:36 +03:00
|
|
|
|
2004-10-15 20:31:54 +04:00
|
|
|
|
|
|
|
COMPLETE:
|
|
|
|
if (create) { /* if creating the dir tree, overwrite the fields */
|
2005-03-19 02:58:36 +03:00
|
|
|
if (NULL != orte_process_info.tmpdir_base) {
|
|
|
|
free(orte_process_info.tmpdir_base);
|
|
|
|
orte_process_info.tmpdir_base = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != orte_process_info.top_session_dir) {
|
|
|
|
free(orte_process_info.top_session_dir);
|
|
|
|
orte_process_info.top_session_dir = NULL;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL == orte_process_info.tmpdir_base) {
|
2005-03-19 02:58:36 +03:00
|
|
|
orte_process_info.tmpdir_base = strdup(tmp); /* fill in if empty */
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL == orte_process_info.top_session_dir) {
|
2005-03-19 02:58:36 +03:00
|
|
|
orte_process_info.top_session_dir = strdup(frontend);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != proc) {
|
2005-03-19 02:58:36 +03:00
|
|
|
if (create) { /* overwrite if creating */
|
|
|
|
if (NULL != orte_process_info.proc_session_dir) {
|
|
|
|
free(orte_process_info.proc_session_dir);
|
|
|
|
orte_process_info.proc_session_dir = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NULL == orte_process_info.proc_session_dir) {
|
|
|
|
orte_process_info.proc_session_dir = strdup(fulldirpath);
|
|
|
|
}
|
|
|
|
sav = strdup(fulldirpath);
|
|
|
|
free(fulldirpath);
|
|
|
|
fulldirpath = strdup(dirname(sav));
|
|
|
|
free(sav);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != job) {
|
2005-03-19 02:58:36 +03:00
|
|
|
if (create) { /* overwrite if creating */
|
|
|
|
if (NULL != orte_process_info.job_session_dir) {
|
|
|
|
free(orte_process_info.job_session_dir);
|
|
|
|
orte_process_info.job_session_dir = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NULL == orte_process_info.job_session_dir) {
|
|
|
|
orte_process_info.job_session_dir = strdup(fulldirpath);
|
|
|
|
}
|
|
|
|
sav = strdup(fulldirpath);
|
|
|
|
free(fulldirpath);
|
|
|
|
fulldirpath = strdup(dirname(sav));
|
|
|
|
free(sav);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (create) { /* overwrite if creating */
|
2005-03-19 02:58:36 +03:00
|
|
|
if (NULL != orte_process_info.universe_session_dir) {
|
|
|
|
free(orte_process_info.universe_session_dir);
|
|
|
|
orte_process_info.universe_session_dir = NULL;
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL == orte_process_info.universe_session_dir) {
|
|
|
|
orte_process_info.universe_session_dir = strdup(fulldirpath);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_debug_flag) {
|
2005-03-19 02:58:36 +03:00
|
|
|
ompi_output(0, "procdir: %s", orte_process_info.proc_session_dir);
|
|
|
|
ompi_output(0, "jobdir: %s", orte_process_info.job_session_dir);
|
|
|
|
ompi_output(0, "unidir: %s", orte_process_info.universe_session_dir);
|
|
|
|
ompi_output(0, "top: %s", orte_process_info.top_session_dir);
|
|
|
|
ompi_output(0, "tmp: %s", orte_process_info.tmpdir_base);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
if (tmp) {
|
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
if (fulldirpath) {
|
|
|
|
free(fulldirpath);
|
|
|
|
}
|
|
|
|
if (frontend) {
|
2005-03-19 02:58:36 +03:00
|
|
|
free(frontend);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
if (batchname) {
|
2005-03-19 02:58:36 +03:00
|
|
|
free(batchname);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
if (hostname) {
|
2005-03-19 02:58:36 +03:00
|
|
|
free(hostname);
|
|
|
|
}
|
|
|
|
if (universe) {
|
|
|
|
free(universe);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
if (sessions) {
|
2005-03-19 02:58:36 +03:00
|
|
|
free(sessions);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
2005-03-19 02:58:36 +03:00
|
|
|
if (user) {
|
|
|
|
free(user);
|
|
|
|
}
|
|
|
|
|
2004-10-15 20:31:54 +04:00
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_session_dir_finalize()
|
2004-10-15 20:31:54 +04:00
|
|
|
{
|
2005-03-14 23:57:21 +03:00
|
|
|
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);
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_is_empty(orte_process_info.proc_session_dir)) {
|
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: found proc session dir empty - deleting");
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
rmdir(orte_process_info.proc_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: proc session dir not empty - leaving");
|
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_is_empty(orte_process_info.job_session_dir)) {
|
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: found job session dir empty - deleting");
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
rmdir(orte_process_info.job_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: job session dir not empty - leaving");
|
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_is_empty(orte_process_info.universe_session_dir)) {
|
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: found univ session dir empty - deleting");
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
rmdir(orte_process_info.universe_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: univ session dir not empty - leaving");
|
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_is_empty(orte_process_info.top_session_dir)) {
|
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: found top session dir empty - deleting");
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
rmdir(orte_process_info.top_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_debug_flag) {
|
2004-10-15 20:31:54 +04:00
|
|
|
ompi_output(0, "sess_dir_finalize: top session dir not empty - leaving");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_dir_empty(char *pathname)
|
2004-10-15 20:31:54 +04:00
|
|
|
{
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
2004-10-15 20:31:54 +04:00
|
|
|
DIR *dp;
|
|
|
|
struct dirent *ep;
|
|
|
|
char *filenm;
|
2005-04-04 18:19:34 +04:00
|
|
|
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
|
|
|
int ret;
|
|
|
|
struct stat buf;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (NULL == pathname) { /* protect against error */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dp = opendir(pathname);
|
|
|
|
if (NULL == dp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (NULL != (ep = readdir(dp)) ) {
|
|
|
|
/* skip:
|
|
|
|
* - . and ..
|
|
|
|
* - directories
|
|
|
|
* - files starting with "output-"
|
|
|
|
* - universe contact (universe-setup.txt)
|
|
|
|
*/
|
|
|
|
if ((0 != strcmp(ep->d_name, ".")) &&
|
|
|
|
(0 != strcmp(ep->d_name, "..")) &&
|
|
|
|
(0 != strncmp(ep->d_name, "output-", strlen("output-"))) &&
|
|
|
|
(0 != strcmp(ep->d_name, "universe-setup.txt"))) {
|
|
|
|
|
|
|
|
filenm = orte_os_path(false, pathname, ep->d_name, NULL);
|
|
|
|
|
|
|
|
/* make sure it's not a directory */
|
|
|
|
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
|
|
|
if (DT_DIR == ep->d_type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#else /* have dirent.d_type */
|
|
|
|
ret = stat(filenm, &buf);
|
|
|
|
if (ret < 0 || S_ISDIR(buf.st_mode)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* have dirent.d_type */
|
|
|
|
unlink(filenm);
|
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
2005-04-04 18:19:34 +04:00
|
|
|
closedir(dp);
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
2004-11-03 00:48:31 +03:00
|
|
|
char search_path[MAX_PATH];
|
2004-10-22 20:06:05 +04:00
|
|
|
HANDLE file;
|
|
|
|
WIN32_FIND_DATA file_data;
|
|
|
|
TCHAR *file_name;
|
|
|
|
|
|
|
|
if (NULL != pathname) {
|
2004-11-03 00:48:31 +03:00
|
|
|
strncpy(search_path, pathname, strlen(pathname)+1);
|
|
|
|
strncat (search_path, "\\*", 3);
|
|
|
|
file = FindFirstFile(search_path, &file_data);
|
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == file) {
|
|
|
|
FindClose(&file_data);
|
2004-10-22 20:06:05 +04:00
|
|
|
return;
|
2004-11-03 00:48:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2004-10-22 20:06:05 +04:00
|
|
|
if ((0 != strcmp(file_data.cFileName, ".")) &&
|
2004-11-03 00:48:31 +03:00
|
|
|
(0 != strcmp(file_data.cFileName, "..")) &&
|
|
|
|
(!(file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) &&
|
|
|
|
(0 != strncmp(file_data.cFileName,"output-", strlen("output-"))) &&
|
|
|
|
(0 != strcmp(file_data.cFileName,"universe-setup.txt-"))) {
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
file_name = orte_os_path(false, pathname, file_data.cFileName, NULL);
|
2004-11-03 00:48:31 +03:00
|
|
|
DeleteFile(file_name);
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
}
|
2004-11-03 03:30:46 +03:00
|
|
|
if (0 == FindNextFile(file, &file_data)) {
|
2004-10-22 20:06:05 +04:00
|
|
|
empty = true;
|
|
|
|
}
|
2004-11-03 00:48:31 +03:00
|
|
|
} while(!empty);
|
2004-10-22 20:06:05 +04:00
|
|
|
FindClose(&file_data);
|
|
|
|
}
|
|
|
|
#endif
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
/* tests if the directory is empty */
|
2005-03-14 23:57:21 +03:00
|
|
|
static bool orte_is_empty(char *pathname)
|
2004-10-15 20:31:54 +04:00
|
|
|
{
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
2004-10-15 20:31:54 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
return false;
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
2004-11-03 00:48:31 +03:00
|
|
|
char search_path[MAX_PATH];
|
2004-10-22 20:06:05 +04:00
|
|
|
HANDLE file;
|
|
|
|
WIN32_FIND_DATA file_data;
|
|
|
|
|
|
|
|
if (NULL != pathname) {
|
2004-11-03 00:48:31 +03:00
|
|
|
strncpy(search_path, pathname, strlen(pathname)+1);
|
|
|
|
strncat (search_path, "\\*", 3);
|
|
|
|
|
|
|
|
file = FindFirstFile(search_path, &file_data);
|
|
|
|
if (INVALID_HANDLE_VALUE == file) {
|
|
|
|
FindClose(&file_data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != strcmp(file_data.cFileName, ".") || 0 != strcmp(file_data.cFileName, "..")) {
|
|
|
|
FindClose(&file_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-11-03 03:30:46 +03:00
|
|
|
while (0 != FindNextFile(file, &file_data)) {
|
2004-11-03 00:48:31 +03:00
|
|
|
if (0 != strcmp(file_data.cFileName, ".") || 0 != strcmp(file_data.cFileName, "..")) {
|
|
|
|
FindClose(&file_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FindClose(&file_data);
|
|
|
|
return true;
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif /* ifndef WIN32 */
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|