2004-08-24 07:04:41 +04:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
* $Id: ompi_universe_setup_file I/O functions $
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "include/constants.h"
|
|
|
|
|
|
|
|
#include "util/output.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"
|
|
|
|
|
2004-08-30 23:25:14 +04:00
|
|
|
#define OMPI_UNIV_SETUP_FILE_MAX_LINE_LENGTH 1024
|
|
|
|
|
|
|
|
char *ompi_getline(FILE *fp);
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
int ompi_write_universe_setup_file(char *filename)
|
2004-08-24 07:04:41 +04:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen(filename, "w");
|
|
|
|
if (NULL == fp) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
if (NULL == ompi_universe_info.name) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-09-03 20:26:15 +04:00
|
|
|
fprintf(fp, "%s\n", ompi_universe_info.name);
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
if (NULL == ompi_universe_info.host) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-09-03 20:26:15 +04:00
|
|
|
fprintf(fp, "%s\n", ompi_universe_info.host);
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
if (NULL == ompi_universe_info.uid) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-09-03 20:26:15 +04:00
|
|
|
fprintf(fp, "%s\n", ompi_universe_info.uid);
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2004-09-03 23:26:49 +04:00
|
|
|
fprintf(fp, "%d\n", ompi_universe_info.pid);
|
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
if (ompi_universe_info.persistence) {
|
2004-08-30 23:25:14 +04:00
|
|
|
fprintf(fp, "persistent\n");
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2004-08-30 23:25:14 +04:00
|
|
|
fprintf(fp, "non-persistent\n");
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
if (NULL == ompi_universe_info.scope) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-09-03 20:26:15 +04:00
|
|
|
fprintf(fp, "%s\n", ompi_universe_info.scope);
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2004-09-11 16:56:52 +04:00
|
|
|
if (ompi_universe_info.console) {
|
2004-08-30 23:25:14 +04:00
|
|
|
fprintf(fp, "console\n");
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2004-09-11 16:56:52 +04:00
|
|
|
fprintf(fp, "silent\n");
|
2004-08-30 23:25:14 +04:00
|
|
|
}
|
|
|
|
|
2004-09-11 16:56:52 +04:00
|
|
|
if (NULL == ompi_universe_info.seed_contact_info) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
2004-09-11 16:56:52 +04:00
|
|
|
fprintf(fp, "%s\n", ompi_universe_info.seed_contact_info);
|
2004-08-24 07:04:41 +04:00
|
|
|
fclose(fp);
|
2004-08-30 23:25:14 +04:00
|
|
|
|
2004-08-24 07:04:41 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-08-30 23:25:14 +04:00
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
fclose(fp);
|
|
|
|
return OMPI_ERROR;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
int ompi_read_universe_setup_file(char *filename)
|
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;
|
|
|
|
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (NULL == fp) { /* failed on first read - wait and try again */
|
|
|
|
sleep(1);
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (NULL == fp) { /* failed twice - give up */
|
|
|
|
return OMPI_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
ompi_universe_info.name = ompi_getline(fp);
|
|
|
|
if (NULL == ompi_universe_info.name) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
ompi_universe_info.host = ompi_getline(fp);
|
|
|
|
if (NULL == ompi_universe_info.host) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
ompi_universe_info.uid = ompi_getline(fp);
|
|
|
|
if (NULL == ompi_universe_info.uid) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
|
2004-09-03 23:26:49 +04:00
|
|
|
input = ompi_getline(fp);
|
|
|
|
if (NULL == input) {
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
ompi_universe_info.pid = (pid_t)atoi(input);
|
|
|
|
|
2004-08-30 23:25:14 +04:00
|
|
|
input = ompi_getline(fp);
|
|
|
|
if (NULL == input) {
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
if (0 == strncmp(input, "persistent", strlen("persistent"))) {
|
2004-09-03 20:26:15 +04:00
|
|
|
ompi_universe_info.persistence = true;
|
2004-08-30 23:25:14 +04:00
|
|
|
} else if (0 == strncmp(input, "non-persistent", strlen("non-persistent"))) {
|
2004-09-03 20:26:15 +04:00
|
|
|
ompi_universe_info.persistence = false;
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2004-08-30 23:25:14 +04:00
|
|
|
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
|
|
|
|
2004-09-03 20:26:15 +04:00
|
|
|
ompi_universe_info.scope = ompi_getline(fp);
|
|
|
|
if (NULL == ompi_universe_info.scope) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
input = ompi_getline(fp);
|
|
|
|
if (NULL == input) {
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
if (0 == strncmp(input, "silent", strlen("silent"))) {
|
2004-09-11 16:56:52 +04:00
|
|
|
ompi_universe_info.console = false;
|
2004-08-30 23:25:14 +04:00
|
|
|
} else if (0 == strncmp(input, "console", strlen("console"))) {
|
2004-09-11 16:56:52 +04:00
|
|
|
ompi_universe_info.console = true;
|
2004-08-24 07:04:41 +04:00
|
|
|
} else {
|
2004-08-30 23:25:14 +04:00
|
|
|
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
|
|
|
|
2004-09-11 16:56:52 +04:00
|
|
|
ompi_universe_info.seed_contact_info = ompi_getline(fp);
|
|
|
|
if (NULL == ompi_universe_info.seed_contact_info) {
|
2004-08-30 23:25:14 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2004-08-24 07:04:41 +04:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return OMPI_SUCCESS;
|
2004-08-30 23:25:14 +04:00
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
fclose(fp);
|
|
|
|
return OMPI_ERROR;
|
2004-08-24 07:04:41 +04:00
|
|
|
}
|
|
|
|
|
2004-08-30 23:25:14 +04:00
|
|
|
char *ompi_getline(FILE *fp)
|
2004-08-24 07:04:41 +04:00
|
|
|
{
|
2004-08-30 23:25:14 +04:00
|
|
|
char *ret, *buff;
|
|
|
|
char input[OMPI_UNIV_SETUP_FILE_MAX_LINE_LENGTH];
|
|
|
|
|
|
|
|
ret = fgets(input, OMPI_UNIV_SETUP_FILE_MAX_LINE_LENGTH, fp);
|
|
|
|
if (NULL != ret) {
|
|
|
|
input[strlen(input)-1] = '\0'; /* remove newline */
|
|
|
|
buff = strdup(input);
|
|
|
|
return buff;
|
2004-08-24 07:04:41 +04: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
|
|
|
|