⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session_dir.c

📁 MPI stands for the Message Passing Interface. Written by the MPI Forum (a large committee comprising
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana *                         University Research and Technology *                         Corporation.  All rights reserved. * Copyright (c) 2004-2006 The University of Tennessee and The University *                         of Tennessee Research Foundation.  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 "orte_config.h"#include <stdio.h>#ifdef HAVE_PWD_H#include <pwd.h>#endif#include <stddef.h>#include <stdlib.h>#include <string.h>#ifdef HAVE_LIBGEN_H #include <libgen.h>#endif#ifdef HAVE_SYS_PARAM_H#include <sys/param.h>#endif#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#include <sys/stat.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <errno.h>#ifdef HAVE_DIRENT_H#include <dirent.h>#endif#include "orte/orte_constants.h"#include "orte/util/univ_info.h"#include "orte/util/sys_info.h"#include "orte/util/proc_info.h"#include "opal/util/output.h"#include "opal/util/os_path.h"#include "opal/util/os_dirpath.h"#include "opal/util/basename.h"#include "orte/mca/errmgr/errmgr.h"#include "orte/runtime/runtime.h"#include "orte/util/session_dir.h"/******************************* * Local function Declarations *******************************/static int orte_create_dir(char *directory);static bool orte_dir_check_file(const char *root, const char *path);#ifdef __WINDOWS__#define OMPI_DEFAULT_TMPDIR "C:\\TEMP"#else#define OMPI_DEFAULT_TMPDIR "/tmp"#endif#define OMPI_PRINTF_FIX_STRING(a) ((NULL == a) ? "(null)" : a)/**************************** * Funcationality ****************************//* * Check and create the directory requested */static int orte_create_dir(char *directory){#ifndef __WINDOWS__    mode_t my_mode = S_IRWXU;  /* at the least, I need to be able to do anything */#else    mode_t my_mode = _S_IREAD | _S_IWRITE | _S_IEXEC;#endif    int ret;    /* Sanity check before creating the directory with the proper mode,     * Make sure it doesn't exist already */    if( OPAL_ERR_NOT_FOUND != (ret = opal_os_dirpath_access(directory, my_mode)) ) {        /* Failure because opal_os_dirpath_access() indicated that either:         * - The directory exists and we can access it (no need to create it again),          *    return OPAL_SUCCESS, or         * - don't have access rights, return OPAL_ERROR         */        return(ret);    }    /* The directory doesn't exist so create it */    else {	    return(opal_os_dirpath_create(directory, my_mode));    }}/* * Construct the fullpath to the session directory */intorte_session_dir_get_name(char **fulldirpath,                          char **prefix,  /* This will come back as the valid tmp dir */                          char **frontend,                          char *usr, char *hostid,                          char *batchid, char *univ,                           char *job, char *proc) {    char *hostname  = NULL,         *batchname = NULL,        *sessions  = NULL,         *user      = NULL,         *universe  = NULL;    int exit_status = ORTE_SUCCESS;        /* Ensure that system info is set */    orte_sys_info();    /*     * set the 'user' value     */    if( NULL != usr) { /* User specified version */        user = strdup(usr);    }    else {             /* check if it is set elsewhere */        if( NULL != orte_system_info.user)            user = strdup(orte_system_info.user);        else {            /* Couldn't find it, so fail */            exit_status = ORTE_ERROR;            goto cleanup;        }    }    /*     * set the 'hostname'     */    if( NULL != hostid) { /* User specified version */        hostname = strdup(hostid);    }    else {            /* check if it is set elsewhere */        if( NULL != orte_system_info.nodename)            hostname = strdup(orte_system_info.nodename);        else {            /* Couldn't find it, so fail */            exit_status = ORTE_ERROR;            goto cleanup;        }    }        /*     * set the 'batchid'     */    if (NULL != batchid)        batchname = strdup(batchid);    else         batchname = strdup("0");    /*     * set the 'universe'     */    if( NULL != univ) { /* User specified version */         universe = strdup(univ);     }     else {            /* check if it is set elsewhere */         if( NULL != orte_universe_info.name) {             universe = strdup(orte_universe_info.name);         }         else {             ;/* Couldn't find it, so continue with caution */         }     }    /*     * Check: Can't give proc or job without universe     */    if( NULL == universe &&        (NULL != proc ||         NULL != job) ) {        exit_status = ORTE_ERROR;        goto cleanup;    }    /*     * Check: Can't give a proc without a job and universe     */    if( NULL == job &&        NULL != proc) {        exit_status = ORTE_ERROR;        goto cleanup;    }        /*     * get the front part of the session directory     * Will look something like:     *    openmpi-sessions-USERNAME@HOSTNAME_BATCHID     */    if (NULL != orte_process_info.top_session_dir) {        *frontend = strdup(orte_process_info.top_session_dir);    }    else { /* If not set then construct it */        if (0 > asprintf(frontend, "openmpi-sessions-%s@%s_%s", user, hostname, batchname)) {            exit_status = ORTE_ERROR;            goto cleanup;        }    }    /*     * Construct the session directory     */    /* If we were given a 'proc' then we can construct it fully into:     *   openmpi-sessions-USERNAME@HOSTNAME_BATCHID/UNIVERSE/JOBID/PROC     */    if( NULL != proc) {        sessions = opal_os_path( false, *frontend, universe, job, proc, NULL );        if( NULL == sessions ) {            exit_status = ORTE_ERROR;            goto cleanup;        }    }    /* If we were given a 'job' then we can construct it partially into:     *   openmpi-sessions-USERNAME@HOSTNAME_BATCHID/UNIVERSE/JOBID     */    else if(NULL != job) {        sessions = opal_os_path( false, *frontend, universe, job, NULL );        if( NULL == sessions ) {            exit_status = ORTE_ERROR;            goto cleanup;        }    }    /* If we were given neither then we can construct it partially into:     *   openmpi-sessions-USERNAME@HOSTNAME_BATCHID/UNIVERSE     */    else if(NULL != universe) {        sessions = opal_os_path( false, *frontend, universe, NULL );        if( NULL == sessions ) {            exit_status = ORTE_ERROR;            goto cleanup;        }    }    /* If we were not given 'universe' then we can construct it into:     *   openmpi-sessions-USERNAME@HOSTNAME_BATCHID     */    else {        if (0 > asprintf(&sessions, "%s",                         *frontend) ) {            exit_status = ORTE_ERROR;            goto cleanup;        }    }        /*     * If the user specified an invalid prefix, or no prefix at all     * we need to keep looking     */    if( NULL != *fulldirpath) {        free(*fulldirpath);        *fulldirpath = NULL;    }    if( NULL != *prefix) { /* use the user specified one, if available */        ;    }    /* Try to find a proper alternative prefix */    else if (NULL != orte_process_info.tmpdir_base) { /* stored value */        *prefix = strdup(orte_process_info.tmpdir_base);    }    else if( NULL != getenv("OMPI_PREFIX_ENV") ) { /* OMPI Environment var */        *prefix = strdup(getenv("OMPI_PREFIX_ENV"));    }    else if( NULL != getenv("TMPDIR") ) { /* General Environment var */        *prefix = strdup(getenv("TMPDIR"));    }    else if( NULL != getenv("TMP") ) { /* Another general environment var */        *prefix = strdup(getenv("TMP"));    }    else { /* ow. just use the default tmp directory */        *prefix = strdup(OMPI_DEFAULT_TMPDIR);    }        /*     * Construct the absolute final path     */    *fulldirpath = opal_os_path(false, *prefix, sessions, NULL);     cleanup:    if(NULL != hostname)        free(hostname);    if(NULL != batchname)        free(batchname);    if(NULL != sessions)        free(sessions);    if(NULL != user)        free(user);    if(NULL != universe)        free(universe);        return exit_status;}/* * Construct the session directory and create it if necessary */int orte_session_dir(bool create,                      char *prefix, char *usr, char *hostid,                     char *batchid, char *univ, char *job, char *proc){    char *fulldirpath = NULL,        *frontend     = NULL,        *sav          = NULL;    int return_code = ORTE_SUCCESS, rtn;    /* This indicates if the prefix was set, and so if it fails then we     * should try with the default prefixes.*/    bool dbl_check_prefix = false;    if( NULL != prefix)        dbl_check_prefix = true; try_again:    /*     * If the first attempt at the path creation failed, try with a null     * prefix. unless the original prefix was null, then we fail.     */    if(!dbl_check_prefix && /* an indicator that we are trying a second time */       NULL != prefix) {        free(prefix);        prefix = NULL;    }        /*     * Get the session directory full name     * First try it with the specified prefix.     */    if( ORTE_SUCCESS != ( rtn = orte_session_dir_get_name(&fulldirpath,                                                           &prefix,                                                          &frontend,                                                          usr, hostid,                                                           batchid, univ, job,                                                          proc) ) ) {        return_code = rtn;        /*         * If the first attempt at the path creation failed, try with a null         * prefix. unless the original prefix was null, then we fail :(         */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -