2004-10-15 20:31:54 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. 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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/orte_constants.h"
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/util/univ_info.h"
|
|
|
|
#include "orte/util/sys_info.h"
|
|
|
|
#include "orte/util/proc_info.h"
|
2005-07-04 03:31:27 +04:00
|
|
|
#include "opal/util/output.h"
|
2005-07-04 05:59:52 +04:00
|
|
|
#include "opal/util/os_path.h"
|
|
|
|
#include "opal/util/os_create_dirpath.h"
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
#include "orte/runtime/runtime.h"
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/util/session_dir.h"
|
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
|
|
|
|
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-12-12 23:04:00 +03:00
|
|
|
#ifdef __WINDOWS__
|
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
|
|
|
|
2005-06-27 03:11:37 +04:00
|
|
|
#define OMPI_PRINTF_FIX_STRING(a) ((NULL == a) ? "(null)" : a)
|
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
|
|
|
{
|
2005-12-12 23:04:00 +03:00
|
|
|
#ifndef __WINDOWS__
|
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
|
|
|
|
2005-12-12 23:04:00 +03:00
|
|
|
#ifndef __WINDOWS__
|
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 */
|
2005-08-15 22:25:35 +04:00
|
|
|
return(ORTE_SUCCESS);
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (create) {
|
2005-07-04 05:59:52 +04:00
|
|
|
return(opal_os_create_dirpath(directory, my_mode)); /* try to create it with proper mode */
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
2005-08-15 22:25:35 +04:00
|
|
|
return(ORTE_ERROR); /* couldn't find it, or don't have access rights, and not asked to create it */
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
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 */
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_ERROR;
|
2005-03-19 02:58:36 +03:00
|
|
|
} 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 */
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_ERROR;
|
2005-03-19 02:58:36 +03:00
|
|
|
} 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-08-15 22:25:35 +04:00
|
|
|
return ORTE_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 */
|
2005-08-15 22:25:35 +04:00
|
|
|
return_code = ORTE_ERROR;
|
2005-03-19 02:58:36 +03:00
|
|
|
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)) {
|
2005-08-15 22:25:35 +04:00
|
|
|
return_code = ORTE_ERROR;
|
2005-03-19 02:58:36 +03:00
|
|
|
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)) {
|
2005-08-15 22:25:35 +04:00
|
|
|
return_code = ORTE_ERROR;
|
2005-03-19 02:58:36 +03:00
|
|
|
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)) {
|
2005-08-15 22:25:35 +04:00
|
|
|
return_code = ORTE_ERROR;
|
2005-03-19 02:58:36 +03:00
|
|
|
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)) {
|
2005-08-15 22:25:35 +04:00
|
|
|
return_code = ORTE_ERROR;
|
2005-03-19 02:58:36 +03:00
|
|
|
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);
|
2005-07-04 05:59:52 +04:00
|
|
|
fulldirpath = strdup(opal_os_path(false, tmp, sessions, NULL)); /* make sure it's an absolute pathname */
|
2005-08-15 22:25:35 +04:00
|
|
|
if (ORTE_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = ORTE_SUCCESS;
|
2005-03-19 02:58:36 +03:00
|
|
|
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);
|
2005-08-30 01:35:01 +04:00
|
|
|
fulldirpath = opal_os_path(false, tmp, sessions, NULL);
|
2005-08-15 22:25:35 +04:00
|
|
|
if (ORTE_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = ORTE_SUCCESS;
|
2005-03-19 02:58:36 +03:00
|
|
|
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"));
|
2005-07-04 05:59:52 +04:00
|
|
|
fulldirpath = strdup(opal_os_path(false, tmp, sessions, NULL));
|
2005-08-15 22:25:35 +04:00
|
|
|
if (ORTE_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = ORTE_SUCCESS;
|
2005-03-19 02:58:36 +03:00
|
|
|
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"));
|
2005-07-04 05:59:52 +04:00
|
|
|
fulldirpath = strdup(opal_os_path(false, tmp, sessions, NULL));
|
2005-08-15 22:25:35 +04:00
|
|
|
if (ORTE_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = ORTE_SUCCESS;
|
2005-03-19 02:58:36 +03:00
|
|
|
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"));
|
2005-07-04 05:59:52 +04:00
|
|
|
fulldirpath = strdup(opal_os_path(false, tmp, sessions, NULL));
|
2005-08-15 22:25:35 +04:00
|
|
|
if (ORTE_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = ORTE_SUCCESS;
|
2005-03-19 02:58:36 +03:00
|
|
|
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);
|
2005-08-30 03:05:52 +04:00
|
|
|
fulldirpath = opal_os_path(false, tmp, sessions, NULL);
|
2005-08-15 22:25:35 +04:00
|
|
|
if (ORTE_SUCCESS == orte_check_dir(create, fulldirpath)) { /* check for existence and access, or create it */
|
|
|
|
return_code = ORTE_SUCCESS;
|
2005-03-19 02:58:36 +03:00
|
|
|
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 */
|
2005-08-15 22:25:35 +04:00
|
|
|
return_code = ORTE_ERROR;
|
2004-10-15 20:31:54 +04:00
|
|
|
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-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "procdir: %s",
|
2005-06-27 03:11:37 +04:00
|
|
|
OMPI_PRINTF_FIX_STRING(orte_process_info.proc_session_dir));
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "jobdir: %s",
|
2005-06-27 03:11:37 +04:00
|
|
|
OMPI_PRINTF_FIX_STRING(orte_process_info.job_session_dir));
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "unidir: %s",
|
2005-06-27 03:11:37 +04:00
|
|
|
OMPI_PRINTF_FIX_STRING(orte_process_info.universe_session_dir));
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "top: %s",
|
2005-06-27 03:11:37 +04:00
|
|
|
OMPI_PRINTF_FIX_STRING(orte_process_info.top_session_dir));
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "tmp: %s",
|
2005-06-27 03:11:37 +04:00
|
|
|
OMPI_PRINTF_FIX_STRING(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-04-14 05:04:26 +04:00
|
|
|
orte_session_dir_finalize(orte_process_name_t *proc)
|
2004-10-15 20:31:54 +04:00
|
|
|
{
|
2005-04-14 05:04:26 +04:00
|
|
|
int rc;
|
2005-04-07 23:19:48 +04:00
|
|
|
char *tmp;
|
2005-04-14 05:04:26 +04:00
|
|
|
char *job, *job_session_dir, *vpid, *proc_session_dir;
|
2005-05-13 01:44:23 +04:00
|
|
|
|
2005-04-07 23:19:48 +04:00
|
|
|
/* need to setup the top_session_dir with the prefix */
|
2005-08-30 01:35:01 +04:00
|
|
|
tmp = opal_os_path(false,
|
|
|
|
orte_process_info.tmpdir_base,
|
|
|
|
orte_process_info.top_session_dir, NULL);
|
2005-04-07 23:19:48 +04:00
|
|
|
|
2005-04-14 05:04:26 +04:00
|
|
|
/* 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);
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_dir_empty(orte_process_info.universe_session_dir);
|
2005-04-07 23:19:48 +04:00
|
|
|
orte_dir_empty(tmp);
|
2004-10-15 20:31:54 +04:00
|
|
|
|
2005-04-14 05:04:26 +04:00
|
|
|
if (orte_is_empty(proc_session_dir)) {
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: found proc session dir empty - deleting");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
2005-04-14 05:04:26 +04:00
|
|
|
rmdir(proc_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: proc session dir not empty - leaving");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
2005-04-14 05:04:26 +04:00
|
|
|
goto CLEANUP;
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-04-14 05:04:26 +04:00
|
|
|
if (orte_is_empty(job_session_dir)) {
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: found job session dir empty - deleting");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
2005-04-14 05:04:26 +04:00
|
|
|
rmdir(job_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: job session dir not empty - leaving");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
2005-04-14 05:04:26 +04:00
|
|
|
goto CLEANUP;
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_is_empty(orte_process_info.universe_session_dir)) {
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: found univ session dir empty - deleting");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
|
|
|
rmdir(orte_process_info.universe_session_dir);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: univ session dir not empty - leaving");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
2005-04-14 05:04:26 +04:00
|
|
|
goto CLEANUP;
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_is_empty(tmp)) {
|
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: found top session dir empty - deleting");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
|
|
|
rmdir(tmp);
|
2004-10-15 20:31:54 +04:00
|
|
|
} else {
|
2005-04-07 23:19:48 +04:00
|
|
|
if (orte_debug_flag) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "sess_dir_finalize: top session dir not empty - leaving");
|
2005-04-07 23:19:48 +04:00
|
|
|
}
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2005-04-14 05:04:26 +04:00
|
|
|
CLEANUP:
|
2005-04-07 23:19:48 +04:00
|
|
|
free(tmp);
|
2005-04-14 05:04:26 +04:00
|
|
|
free(job);
|
|
|
|
free(vpid);
|
|
|
|
free(job_session_dir);
|
|
|
|
free(proc_session_dir);
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_dir_empty(char *pathname)
|
2004-10-15 20:31:54 +04:00
|
|
|
{
|
2005-12-12 23:04:00 +03:00
|
|
|
#ifndef __WINDOWS__
|
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"))) {
|
|
|
|
|
2005-07-04 05:59:52 +04:00
|
|
|
filenm = opal_os_path(false, pathname, ep->d_name, NULL);
|
2005-04-04 18:19:34 +04:00
|
|
|
|
|
|
|
/* make sure it's not a directory */
|
|
|
|
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
|
|
|
if (DT_DIR == ep->d_type) {
|
2005-08-30 01:35:01 +04:00
|
|
|
free(filenm);
|
2005-04-04 18:19:34 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#else /* have dirent.d_type */
|
|
|
|
ret = stat(filenm, &buf);
|
|
|
|
if (ret < 0 || S_ISDIR(buf.st_mode)) {
|
2005-08-30 01:35:01 +04:00
|
|
|
free(filenm);
|
2005-04-04 18:19:34 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* have dirent.d_type */
|
|
|
|
unlink(filenm);
|
2005-08-30 01:35:01 +04:00
|
|
|
free(filenm);
|
2005-04-04 18:19:34 +04:00
|
|
|
}
|
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
|
2005-04-11 08:47:58 +04:00
|
|
|
bool empty = false;
|
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-07-04 05:59:52 +04:00
|
|
|
file_name = opal_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
|
|
|
{
|
2005-12-12 23:04:00 +03:00
|
|
|
#ifndef __WINDOWS__
|
2004-10-15 20:31:54 +04:00
|
|
|
DIR *dp;
|
|
|
|
struct dirent *ep;
|
|
|
|
if (NULL != pathname) { /* protect against error */
|
2005-04-07 23:19:48 +04:00
|
|
|
dp = opendir(pathname);
|
|
|
|
if (NULL != dp) {
|
|
|
|
while ((ep = readdir(dp))) {
|
|
|
|
if ((0 != strcmp(ep->d_name, ".")) &&
|
|
|
|
(0 != strcmp(ep->d_name, ".."))) {
|
2005-08-30 01:35:01 +04:00
|
|
|
closedir(dp);
|
2005-04-07 23:19:48 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
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;
|
2005-12-12 23:04:00 +03:00
|
|
|
#endif /* ifndef __WINDOWS__ */
|
2004-10-15 20:31:54 +04:00
|
|
|
}
|