コード例 #1
0
ファイル: shfp_fname.c プロジェクト: ParaStation/psmpi2
void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code)
{
    int len;
    char *slash, *ptr, tmp[PATH_MAX];

    fd->shared_fp_fname = (char *) ADIOI_Malloc(PATH_MAX);

    if (!rank) {
        MPL_create_pathname(tmp, NULL, ".shfp", 0);

        if (ADIOI_Strncpy(fd->shared_fp_fname, fd->filename, PATH_MAX)) {
            *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname", fd->filename, ENAMETOOLONG);
            return;
        }
#ifdef ROMIO_NTFS
        slash = strrchr(fd->filename, '\\');
#else
        slash = strrchr(fd->filename, '/');
#endif
        if (!slash) {
            if (ADIOI_Strncpy(fd->shared_fp_fname, ".", 2)) {
                *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname", fd->filename, ENAMETOOLONG);
                return;
            }
            if (ADIOI_Strncpy(fd->shared_fp_fname + 1, fd->filename, PATH_MAX - 1)) {
                *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname", fd->filename, ENAMETOOLONG);
                return;
            }
        } else {
            ptr = slash;
#ifdef ROMIO_NTFS
            slash = strrchr(fd->shared_fp_fname, '\\');
#else
            slash = strrchr(fd->shared_fp_fname, '/');
#endif
            if (ADIOI_Strncpy(slash + 1, ".", 2)) {
                *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname", fd->filename, ENAMETOOLONG);
                return;
            }
            /* ok to cast: file names bounded by PATH_MAX and NAME_MAX */
            len = (int) (PATH_MAX - (slash + 2 - fd->shared_fp_fname));
            if (ADIOI_Strncpy(slash + 2, ptr + 1, len)) {
                *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname", ptr + 1, ENAMETOOLONG);
                return;
            }
        }

        /* MPL_strnapp will return non-zero if truncated.  That's ok */
        MPL_strnapp(fd->shared_fp_fname, tmp, PATH_MAX);

        len = (int) strlen(fd->shared_fp_fname);
        MPI_Bcast(&len, 1, MPI_INT, 0, fd->comm);
        MPI_Bcast(fd->shared_fp_fname, len + 1, MPI_CHAR, 0, fd->comm);
    } else {
        MPI_Bcast(&len, 1, MPI_INT, 0, fd->comm);
        MPI_Bcast(fd->shared_fp_fname, len + 1, MPI_CHAR, 0, fd->comm);
    }
}
コード例 #2
0
ファイル: mpiexec.c プロジェクト: zhanglt/mpich
static int AddEnvSetToCmdLine( const char *envName, const char *envValue, 
			       const char **args )
{
    int nArgs = 0;
    static int useCSHFormat = -1;
    
    /* Determine the Shell type the first time*/
    if (useCSHFormat == -1) {
	char *shell = getenv( "SHELL" ), *sname;
	if (shell) {
/* 	    printf( "Shell is %s\n", shell ); */
	    sname = strrchr( shell, '/' );
	    if (!sname) sname = shell;
	    else sname++;
/* 	    printf( "Sname is %s\n", sname ); */
	    if (strcmp( sname, "bash" ) == 0 || strcmp( sname, "sh" ) ||
		strcmp( sname, "ash" ) == 0) useCSHFormat = 0;
	    else 
		useCSHFormat = 1;
	}
	else {
	    /* Default is to assume csh (setenv) format */
	    useCSHFormat = 1;
	}
    }

    if (useCSHFormat) {
	args[nArgs++] = MPL_strdup( "setenv" );
	args[nArgs++] = MPL_strdup( envName );
        args[nArgs++] = MPL_strdup( envValue );
	args[nArgs++] = MPL_strdup( ";" );
    }
    else {
	char tmpBuf[1024];
	args[nArgs++] = MPL_strdup( "export" );
	MPL_strncpy( tmpBuf, envName, sizeof(tmpBuf) );
	MPL_strnapp( tmpBuf, "=", sizeof(tmpBuf) );
	MPL_strnapp( tmpBuf, envValue, sizeof(tmpBuf) );
	args[nArgs++] = MPL_strdup( tmpBuf );
	args[nArgs++] = MPL_strdup( ";" );
    }
    return nArgs;
}
コード例 #3
0
ファイル: file_nameserv.c プロジェクト: jeffhammond/mpich
/* Create a structure that we will use to remember files created for
   publishing.  */
int MPID_NS_Create(const MPIR_Info * info_ptr, MPID_NS_Handle * handle_ptr)
{
    const char *dirname;
    struct stat st;
    int err, ret;

    *handle_ptr = (MPID_NS_Handle) MPL_malloc(sizeof(struct MPID_NS_Handle), MPL_MEM_PM);
    /* --BEGIN ERROR HANDLING-- */
    if (!*handle_ptr) {
        err =
            MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, __func__, __LINE__,
                                 MPI_ERR_OTHER, "**nomem", 0);
        return err;
    }
    /* --END ERROR HANDLING-- */
    (*handle_ptr)->nactive = 0;
    (*handle_ptr)->mypid = getpid();

    /* Get the dirname.  Could use an info value of NAMEPUB_CONTACT */
    dirname = MPIR_CVAR_NAMESERV_FILE_PUBDIR;
    if (!dirname) {
        /* user did not specify a directory, try using HOME */
        ret = MPL_env2str("HOME", &dirname);
        if (!ret) {
            /* HOME not found ; use current directory */
            dirname = ".";
        }
    }

    MPL_strncpy((*handle_ptr)->dirname, dirname, MAXPATHLEN);
    MPL_strnapp((*handle_ptr)->dirname, "/.mpinamepub/", MAXPATHLEN);

    /* Make the directory if necessary */
    /* FIXME : Determine if the directory exists before trying to create it */

    if (stat((*handle_ptr)->dirname, &st) || !S_ISDIR(st.st_mode)) {
        /* This mode is rwx by owner only.  */
        if (mkdir((*handle_ptr)->dirname, 0000700)) {
            /* FIXME : An error.  Ignore most ?
             * For example, ignore EEXIST?  */
            ;
        }
    }

    return 0;
}
コード例 #4
0
ファイル: file_nameserv.c プロジェクト: jeffhammond/mpich
int MPID_NS_Lookup(MPID_NS_Handle handle, const MPIR_Info * info_ptr,
                   const char service_name[], char port[])
{
    FILE *fp;
    char filename[MAXPATHLEN];
    int mpi_errno = MPI_SUCCESS;

    /* Determine file and directory name.  The file name is from
     * the service name */
    MPL_strncpy(filename, handle->dirname, MAXPATHLEN);
    MPL_strnapp(filename, service_name, MAXPATHLEN);

    fp = fopen(filename, "r");
    if (!fp) {
        /* --BEGIN ERROR HANDLING-- */
        port[0] = 0;
        MPIR_ERR_SET1(mpi_errno, MPI_ERR_NAME,
                      "**namepubnotpub", "**namepubnotpub %s", service_name);
        /* --END ERROR HANDLING-- */
    } else {
        /* The first line is the name, the second is the
         * process that published. We just read the name */
        if (!fgets(port, MPI_MAX_PORT_NAME, fp)) {
            /* --BEGIN ERROR HANDLING-- */
            port[0] = 0;
            MPIR_ERR_SET1(mpi_errno, MPI_ERR_NAME,
                          "**namepubnotfound", "**namepubnotfound %s", service_name);
            /* --END ERROR HANDLING-- */
        } else {
            char *nl;
            /* Remove the newline, if any.  We use fgets instead of fscanf
             * to allow port names to contain blanks */
            nl = strchr(port, '\n');
            if (nl)
                *nl = 0;
            /* printf("Read %s from %s\n", port, filename); */
        }
        fclose(fp);
    }
    return mpi_errno;
}
コード例 #5
0
ファイル: file_nameserv.c プロジェクト: jeffhammond/mpich
int MPID_NS_Unpublish(MPID_NS_Handle handle, const MPIR_Info * info_ptr, const char service_name[])
{
    char filename[MAXPATHLEN];
    int err;
    int i;

    /* Remove the file corresponding to the service name */
    /* Determine file and directory name.  The file name is from
     * the service name */
    MPL_strncpy(filename, handle->dirname, MAXPATHLEN);
    MPL_strnapp(filename, service_name, MAXPATHLEN);

    /* Find the filename from the list of published files */
    for (i = 0; i < handle->nactive; i++) {
        if (handle->filenames[i] && strcmp(filename, handle->filenames[i]) == 0) {
            /* unlink the file only if we find it */
            unlink(filename);
            MPL_free(handle->filenames[i]);
            handle->filenames[i] = 0;
            break;
        }
    }

    if (i == handle->nactive) {
        /* --BEGIN ERROR HANDLING-- */
        /* Error: this name was not found */
        err = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, __func__, __LINE__,
                                   MPI_ERR_SERVICE, "**namepubnotpub",
                                   "**namepubnotpub %s", service_name);
        return err;
        /* --END ERROR HANDLING-- */
    }

    /* Later, we can reduce the number of active and compress the list */

    return 0;
}
コード例 #6
0
ファイル: file_nameserv.c プロジェクト: jeffhammond/mpich
int MPID_NS_Publish(MPID_NS_Handle handle, const MPIR_Info * info_ptr,
                    const char service_name[], const char port[])
{
    FILE *fp;
    char filename[MAXPATHLEN];
    int err;

    /* Determine file and directory name.  The file name is from
     * the service name */
    MPL_strncpy(filename, handle->dirname, MAXPATHLEN);
    MPL_strnapp(filename, service_name, MAXPATHLEN);

    /* Add the file name to the known files now, in case there is
     * a failure during open or writing */
    if (handle->nactive < MPID_MAX_NAMEPUB) {
        handle->filenames[handle->nactive++] = MPL_strdup(filename);
    } else {
        /* --BEGIN ERROR HANDLING-- */
        err = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
                                   __func__, __LINE__, MPI_ERR_OTHER, "**nomem", 0);
        return err;
        /* --END ERROR HANDLING-- */
    }

    /* Now, open the file and write out the port name */
    fp = fopen(filename, "w");
    /* --BEGIN ERROR HANDLING-- */
    if (!fp) {
        char *reason;
        /* Generate a better error message */
        /* Check for errno =
         * EACCES (access denied to file or a dir),
         * ENAMETOOLONG (name too long)
         * ENOENT (no such directory)
         * ENOTDIR (a name in the path that should have been a directory
         * wasn't)
         * ELOOP (too many symbolic links in path)
         * ENOMEM (insufficient kernel memory available)
         * There are a few others that aren't covered here
         */
#ifdef HAVE_STRERROR
        reason = strerror(errno);
#else
        /* FIXME : This should use internationalization calls */
        switch (errno) {
            case EACCES:
                reason = "Access denied to some element of the path";
                break;
            case ENAMETOOLONG:
                reason = "File name is too long";
                break;
            case ENOENT:
                reason = "A directory specified in the path does not exist";
                break;
            case ENOTDIR:
                reason =
                    "A name specified in the path exists, but is not a directory and is used where a directory is required";
                break;
            case ENOMEM:
                reason "Insufficient kernel memory available";
            default:
                MPL_snprintf(rstr, sizeof(rstr), "errno = %d", errno);
        }
#endif
        err = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, __func__, __LINE__,
                                   MPI_ERR_OTHER, "**namepubfile",
                                   "**namepubfile %s %s %s", service_name, filename, reason);
        return err;
    }
    /* --END ERROR HANDLING-- */
    /* Should also add date? */
    fprintf(fp, "%s\n%d\n", port, handle->mypid);
    fclose(fp);

    return 0;
}