2004-08-24 07:04:41 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03: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-08-24 07:04:41 +04:00
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*
|
2005-03-14 23:57:21 +03:00
|
|
|
* $Id: orte_universe_setup_file I/O functions $
|
2004-08-24 07:04:41 +04:00
|
|
|
*
|
|
|
|
*/
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "orte_config.h"
|
2004-08-24 07:04:41 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-08-24 07:04:41 +04:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-08-24 07:04:41 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-08-24 07:04:41 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "include/orte_constants.h"
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-07-04 03:31:27 +04:00
|
|
|
#include "opal/util/output.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "util/univ_info.h"
|
2005-05-20 19:50:27 +04:00
|
|
|
#include "mca/errmgr/errmgr.h"
|
2004-09-03 20:26:15 +04:00
|
|
|
#include "runtime/runtime.h"
|
2004-08-24 07:04:41 +04:00
|
|
|
#include "util/universe_setup_file_io.h"
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
#define ORTE_UNIV_SETUP_FILE_MAX_LINE_LENGTH 1024
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
static char *orte_getline(FILE *fp);
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
int orte_write_universe_setup_file(char *filename, orte_universe_t *info)
|
2004-08-24 07:04:41 +04:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen(filename, "w");
|
|
|
|
if (NULL == fp) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_OPEN_FAILURE);
|
|
|
|
return ORTE_ERR_FILE_OPEN_FAILURE;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
if (NULL == info->name) {
|
2005-03-14 23:57:21 +03:00
|
|
|
/* fatal error - must have a name */
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_VALUE_OUT_OF_BOUNDS);
|
2005-03-14 23:57:21 +03:00
|
|
|
fclose(fp);
|
2005-05-20 19:50:27 +04:00
|
|
|
return ORTE_ERR_VALUE_OUT_OF_BOUNDS;
|
2005-03-14 23:57:21 +03:00
|
|
|
} else {
|
2005-05-05 23:14:51 +04:00
|
|
|
fprintf(fp, "%s\n", info->name);
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
if (NULL == info->host) {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "LOCALHOST\n");
|
|
|
|
} else {
|
2005-05-05 23:14:51 +04:00
|
|
|
fprintf(fp, "%s\n", info->host);
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
if (NULL == info->uid) {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "NO-UID\n");
|
|
|
|
} else {
|
2005-05-05 23:14:51 +04:00
|
|
|
fprintf(fp, "%s\n", info->uid);
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
if (info->persistence) {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "persistent\n");
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "non-persistent\n");
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
if (NULL == info->scope) {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "NO-SCOPE\n");
|
|
|
|
} else {
|
2005-05-05 23:14:51 +04:00
|
|
|
fprintf(fp, "%s\n", info->scope);
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
if (info->console) {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "console\n");
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "silent\n");
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
if (NULL == info->seed_uri) {
|
2005-03-14 23:57:21 +03:00
|
|
|
fprintf(fp, "NO-SEED-URI\n");
|
|
|
|
} else {
|
2005-05-05 23:14:51 +04:00
|
|
|
fprintf(fp, "%s\n", info->seed_uri);
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2004-08-24 07:04:41 +04:00
|
|
|
fclose(fp);
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
return ORTE_SUCCESS;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
int orte_read_universe_setup_file(char *filename, orte_universe_t *info)
|
2004-08-24 07:04:41 +04:00
|
|
|
{
|
2004-08-30 23:25:14 +04:00
|
|
|
char *input;
|
2004-08-24 07:04:41 +04:00
|
|
|
FILE *fp;
|
2005-05-20 19:50:27 +04:00
|
|
|
int rc;
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-05-20 20:26:42 +04:00
|
|
|
/* initialize the universe structure */
|
|
|
|
memset(info, 0, sizeof(orte_universe_t));
|
|
|
|
|
2004-08-24 07:04:41 +04:00
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (NULL == fp) { /* failed on first read - wait and try again */
|
2005-03-14 23:57:21 +03:00
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (NULL == fp) { /* failed twice - give up */
|
2005-05-20 19:50:27 +04:00
|
|
|
return ORTE_ERR_FILE_OPEN_FAILURE;
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
|
|
|
|
2005-05-19 23:15:41 +04:00
|
|
|
/* fill in universe info */
|
2005-05-05 23:14:51 +04:00
|
|
|
info->name = orte_getline(fp);
|
|
|
|
if (NULL == info->name) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
info->host = orte_getline(fp);
|
|
|
|
if (NULL == info->host) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2005-05-05 23:14:51 +04:00
|
|
|
} else if (0 == strcmp("LOCALHOST", info->host)) {
|
|
|
|
free(info->host);
|
|
|
|
info->host = NULL;
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
info->uid = orte_getline(fp);
|
|
|
|
if (NULL == info->uid) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2005-05-05 23:14:51 +04:00
|
|
|
} else if (0 == strcmp("NO-UID", info->uid)) {
|
|
|
|
free(info->uid);
|
|
|
|
info->uid = NULL;
|
2004-09-03 23:26:49 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
input = orte_getline(fp);
|
2004-08-30 23:25:14 +04:00
|
|
|
if (NULL == input) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
if (0 == strncmp(input, "persistent", strlen("persistent"))) {
|
2005-05-05 23:14:51 +04:00
|
|
|
info->persistence = true;
|
2004-08-30 23:25:14 +04:00
|
|
|
} else if (0 == strncmp(input, "non-persistent", strlen("non-persistent"))) {
|
2005-05-05 23:14:51 +04:00
|
|
|
info->persistence = false;
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_VALUE_OUT_OF_BOUNDS);
|
|
|
|
rc = ORTE_ERR_VALUE_OUT_OF_BOUNDS;
|
|
|
|
free(input);
|
|
|
|
goto CLEANUP;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2004-08-30 23:25:14 +04:00
|
|
|
free(input);
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
info->scope = orte_getline(fp);
|
|
|
|
if (NULL == info->scope) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2005-05-05 23:14:51 +04:00
|
|
|
} else if (0 == strcmp("NO-SCOPE", info->scope)) {
|
|
|
|
free(info->scope);
|
|
|
|
info->scope = strdup("exclusive");
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
input = orte_getline(fp);
|
2004-08-30 23:25:14 +04:00
|
|
|
if (NULL == input) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
if (0 == strncmp(input, "silent", strlen("silent"))) {
|
2005-05-05 23:14:51 +04:00
|
|
|
info->console = false;
|
2004-08-30 23:25:14 +04:00
|
|
|
} else if (0 == strncmp(input, "console", strlen("console"))) {
|
2005-05-05 23:14:51 +04:00
|
|
|
info->console = true;
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
free(input);
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_VALUE_OUT_OF_BOUNDS);
|
|
|
|
rc = ORTE_ERR_VALUE_OUT_OF_BOUNDS;
|
|
|
|
goto CLEANUP;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2004-08-30 23:25:14 +04:00
|
|
|
free(input);
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2005-05-05 23:14:51 +04:00
|
|
|
info->seed_uri = orte_getline(fp);
|
|
|
|
if (NULL == info->seed_uri) {
|
2005-05-20 19:50:27 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2005-05-05 23:14:51 +04:00
|
|
|
} else if (0 == strcmp("NO-SEED-URI", info->seed_uri)) {
|
|
|
|
free(info->seed_uri);
|
|
|
|
info->seed_uri = NULL;
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
|
|
|
|
fclose(fp);
|
2005-03-14 23:57:21 +03:00
|
|
|
return ORTE_SUCCESS;
|
2004-08-30 23:25:14 +04:00
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
fclose(fp);
|
2005-03-14 23:57:21 +03:00
|
|
|
return ORTE_ERROR;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
static char *orte_getline(FILE *fp)
|
2004-08-24 07:04:41 +04:00
|
|
|
{
|
2004-08-30 23:25:14 +04:00
|
|
|
char *ret, *buff;
|
2005-03-14 23:57:21 +03:00
|
|
|
char input[ORTE_UNIV_SETUP_FILE_MAX_LINE_LENGTH];
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
ret = fgets(input, ORTE_UNIV_SETUP_FILE_MAX_LINE_LENGTH, fp);
|
2004-08-30 23:25:14 +04:00
|
|
|
if (NULL != ret) {
|
2005-03-14 23:57:21 +03:00
|
|
|
input[strlen(input)-1] = '\0'; /* remove newline */
|
|
|
|
buff = strdup(input);
|
|
|
|
return buff;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2004-08-30 23:25:14 +04:00
|
|
|
return NULL;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2004-08-30 23:25:14 +04:00
|
|
|
|