1
1

Style changes only (this was originally written before many of the

style guidelines existed) so that the next patch concentrates on
fixes / functionality changes

This commit was SVN r7249.
Этот коммит содержится в:
Jeff Squyres 2005-09-09 09:38:43 +00:00
родитель 778468a5b6
Коммит eeee36aa73
2 изменённых файлов: 667 добавлений и 656 удалений

Просмотреть файл

@ -19,6 +19,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
@ -40,25 +41,25 @@
*/
static int verbose_stream = -1;
static opal_output_stream_t verbose = {
/* debugging */
false,
/* verbose level */
0,
/* syslog */
false, 0, NULL, NULL,
/* stdout */
false,
/* stderr */
true,
/* file */
false, false, NULL
/* debugging */
false,
/* verbose level */
0,
/* syslog */
false, 0, NULL, NULL,
/* stdout */
false,
/* stderr */
true,
/* file */
false, false, NULL
};
/*
* Private functions
*/
static int do_open(int output_id, opal_output_stream_t *lds);
static int do_open(int output_id, opal_output_stream_t * lds);
static int open_file(int i);
static void free_descriptor(int output_id);
static void output(int output_id, const char *format, va_list arglist);
@ -68,29 +69,31 @@ static void output(int output_id, const char *format, va_list arglist);
* Internal data structures and helpers for the generalized output
* stream mechanism.
*/
struct output_desc_t {
bool ldi_used;
bool ldi_enabled;
int ldi_verbose_level;
struct output_desc_t
{
bool ldi_used;
bool ldi_enabled;
int ldi_verbose_level;
bool ldi_syslog;
int ldi_syslog_priority;
bool ldi_syslog;
int ldi_syslog_priority;
#ifndef WIN32
char *ldi_syslog_ident;
#else
HANDLE ldi_syslog_ident;
char *ldi_syslog_ident;
#else
HANDLE ldi_syslog_ident;
#endif
char *ldi_prefix;
int ldi_prefix_len;
char *ldi_prefix;
int ldi_prefix_len;
bool ldi_stdout;
bool ldi_stderr;
bool ldi_stdout;
bool ldi_stderr;
bool ldi_file;
bool ldi_file_want_append;
char *ldi_file_suffix;
int ldi_fd;
int ldi_file_num_lines_lost;
bool ldi_file;
bool ldi_file_want_append;
char *ldi_file_suffix;
int ldi_fd;
int ldi_file_num_lines_lost;
};
typedef struct output_desc_t output_desc_t;
@ -113,51 +116,51 @@ static bool syslog_opened = false;
*/
bool opal_output_init(void)
{
int i;
int i;
if (initialized) {
return true;
}
if (initialized) {
return true;
}
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
info[i].ldi_used = false;
info[i].ldi_enabled = false;
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
info[i].ldi_used = false;
info[i].ldi_enabled = false;
info[i].ldi_syslog = false;
info[i].ldi_file = false;
info[i].ldi_file_suffix = NULL;
info[i].ldi_file_want_append = false;
info[i].ldi_fd = -1;
info[i].ldi_file_num_lines_lost = 0;
}
info[i].ldi_syslog = false;
info[i].ldi_file = false;
info[i].ldi_file_suffix = NULL;
info[i].ldi_file_want_append = false;
info[i].ldi_fd = -1;
info[i].ldi_file_num_lines_lost = 0;
}
/* Initialize the mutex that protects the output */
/* Initialize the mutex that protects the output */
OBJ_CONSTRUCT(&mutex, opal_mutex_t);
initialized = true;
OBJ_CONSTRUCT(&mutex, opal_mutex_t);
initialized = true;
/* Open the default verbose stream */
/* Open the default verbose stream */
verbose_stream = opal_output_open(&verbose);
return true;
verbose_stream = opal_output_open(&verbose);
return true;
}
/*
* Open a stream
*/
int opal_output_open(opal_output_stream_t *lds)
int opal_output_open(opal_output_stream_t * lds)
{
return do_open(-1, lds);
return do_open(-1, lds);
}
/*
* Reset the parameters on a stream
*/
int opal_output_reopen(int output_id, opal_output_stream_t *lds)
int opal_output_reopen(int output_id, opal_output_stream_t * lds)
{
return do_open(output_id, lds);
return do_open(output_id, lds);
}
@ -166,19 +169,20 @@ int opal_output_reopen(int output_id, opal_output_stream_t *lds)
*/
bool opal_output_switch(int output_id, bool enable)
{
bool ret = false;
bool ret = false;
/* Setup */
/* Setup */
if (!initialized)
opal_output_init();
if (!initialized) {
opal_output_init();
}
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS) {
ret = info[output_id].ldi_enabled;
info[output_id].ldi_enabled = enable;
}
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS) {
ret = info[output_id].ldi_enabled;
info[output_id].ldi_enabled = enable;
}
return ret;
return ret;
}
@ -187,40 +191,40 @@ bool opal_output_switch(int output_id, bool enable)
*/
void opal_output_reopen_all(void)
{
int i;
opal_output_stream_t lds;
int i;
opal_output_stream_t lds;
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
/* scan till we find ldi_used == 0, which is the end-marker */
/* scan till we find ldi_used == 0, which is the end-marker */
if (!info[i].ldi_used) {
break;
if (!info[i].ldi_used) {
break;
}
/*
* set this to zero to ensure that opal_output_open will
* return this same index as the output stream id
*/
info[i].ldi_used = false;
lds.lds_want_syslog = info[i].ldi_syslog;
lds.lds_syslog_priority = info[i].ldi_syslog_priority;
lds.lds_syslog_ident = info[i].ldi_syslog_ident;
lds.lds_prefix = info[i].ldi_prefix;
lds.lds_want_stdout = info[i].ldi_stdout;
lds.lds_want_stderr = info[i].ldi_stderr;
lds.lds_want_file = (-1 == info[i].ldi_fd) ? false : true;
/* open all streams in append mode */
lds.lds_want_file_append = true;
lds.lds_file_suffix = info[i].ldi_file_suffix;
/*
* call opal_output_open to open the stream. The return value
* is guaranteed to be i. So we can ignore it.
*/
opal_output_open(&lds);
}
/*
* set this to zero to ensure that opal_output_open will return this same
* index as the output stream id
*/
info[i].ldi_used = false;
lds.lds_want_syslog = info[i].ldi_syslog;
lds.lds_syslog_priority = info[i].ldi_syslog_priority;
lds.lds_syslog_ident = info[i].ldi_syslog_ident;
lds.lds_prefix = info[i].ldi_prefix;
lds.lds_want_stdout = info[i].ldi_stdout;
lds.lds_want_stderr = info[i].ldi_stderr;
lds.lds_want_file = (-1 == info[i].ldi_fd) ? false : true;
/* open all streams in append mode */
lds.lds_want_file_append = true;
lds.lds_file_suffix = info[i].ldi_file_suffix;
/*
* call opal_output_open to open the stream. The return value is
* guaranteed to be i. So we can ignore it.
*/
opal_output_open(&lds);
}
}
@ -229,47 +233,47 @@ void opal_output_reopen_all(void)
*/
void opal_output_close(int output_id)
{
int i;
int i;
/* Setup */
/* Setup */
if (!initialized) {
opal_output_init();
}
/* If it's valid, used, enabled, and has an open file descriptor,
free the resources associated with the descriptor */
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS &&
info[output_id].ldi_used &&
info[output_id].ldi_enabled) {
free_descriptor(output_id);
}
/* If no one has the syslog open, we should close it */
OPAL_THREAD_LOCK(&mutex);
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
if (info[i].ldi_used && info[i].ldi_syslog) {
break;
if (!initialized) {
opal_output_init();
}
}
/* If it's valid, used, enabled, and has an open file descriptor,
* free the resources associated with the descriptor */
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS &&
info[output_id].ldi_used && info[output_id].ldi_enabled) {
free_descriptor(output_id);
}
/* If no one has the syslog open, we should close it */
OPAL_THREAD_LOCK(&mutex);
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
if (info[i].ldi_used && info[i].ldi_syslog) {
break;
}
}
#ifndef WIN32
if (i >= OPAL_OUTPUT_MAX_STREAMS && syslog_opened) {
closelog();
}
#else
if (i >= OPAL_OUTPUT_MAX_STREAMS && syslog_opened) {
closelog();
}
#else
DeregisterEventSource(info[output_id].ldi_syslog_ident);
#endif
/* Somewhat of a hack to free up the temp_str */
/* Somewhat of a hack to free up the temp_str */
if (NULL != temp_str) {
free(temp_str);
temp_str = NULL;
temp_str_len = 0;
}
OPAL_THREAD_UNLOCK(&mutex);
if (NULL != temp_str) {
free(temp_str);
temp_str = NULL;
temp_str_len = 0;
}
OPAL_THREAD_UNLOCK(&mutex);
}
@ -278,10 +282,10 @@ void opal_output_close(int output_id)
*/
void opal_output(int output_id, const char *format, ...)
{
va_list arglist;
va_start(arglist, format);
output(output_id, format, arglist);
va_end(arglist);
va_list arglist;
va_start(arglist, format);
output(output_id, format, arglist);
va_end(arglist);
}
@ -290,12 +294,12 @@ void opal_output(int output_id, const char *format, ...)
*/
void opal_output_verbose(int level, int output_id, const char *format, ...)
{
if (info[output_id].ldi_verbose_level >= level) {
va_list arglist;
va_start(arglist, format);
output(output_id, format, arglist);
va_end(arglist);
}
if (info[output_id].ldi_verbose_level >= level) {
va_list arglist;
va_start(arglist, format);
output(output_id, format, arglist);
va_end(arglist);
}
}
@ -304,7 +308,7 @@ void opal_output_verbose(int level, int output_id, const char *format, ...)
*/
void opal_output_set_verbosity(int output_id, int level)
{
info[output_id].ldi_verbose_level = level;
info[output_id].ldi_verbose_level = level;
}
@ -313,13 +317,13 @@ void opal_output_set_verbosity(int output_id, int level)
*/
void opal_output_finalize(void)
{
if (initialized) {
if (verbose_stream != -1) {
opal_output_close(verbose_stream);
if (initialized) {
if (verbose_stream != -1) {
opal_output_close(verbose_stream);
}
verbose_stream = -1;
}
verbose_stream = -1;
}
OBJ_DESTRUCT(&mutex);
OBJ_DESTRUCT(&mutex);
}
/************************************************************************/
@ -329,100 +333,102 @@ void opal_output_finalize(void)
* back-end function so that we can do the thread locking properly
* (especially upon reopen).
*/
static int do_open(int output_id, opal_output_stream_t *lds)
static int do_open(int output_id, opal_output_stream_t * lds)
{
int i;
int i;
/* Setup */
/* Setup */
if (!initialized) {
opal_output_init();
}
/* If output_id == -1, find an available stream, or return
OMPI_ERROR */
if (-1 == output_id) {
OPAL_THREAD_LOCK(&mutex);
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
if (!info[i].ldi_used) {
break;
}
if (!initialized) {
opal_output_init();
}
if (i >= OPAL_OUTPUT_MAX_STREAMS) {
OPAL_THREAD_UNLOCK(&mutex);
return OMPI_ERR_OUT_OF_RESOURCE;
/* If output_id == -1, find an available stream, or return
* OMPI_ERROR */
if (-1 == output_id) {
OPAL_THREAD_LOCK(&mutex);
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
if (!info[i].ldi_used) {
break;
}
}
if (i >= OPAL_OUTPUT_MAX_STREAMS) {
OPAL_THREAD_UNLOCK(&mutex);
return OMPI_ERR_OUT_OF_RESOURCE;
}
}
}
/* Otherwise, we're reopening, so we need to free all previous
resources, close files, etc. */
/* Otherwise, we're reopening, so we need to free all previous
* resources, close files, etc. */
else {
free_descriptor(output_id);
i = output_id;
}
else {
free_descriptor(output_id);
i = output_id;
}
/* Special case: if we got NULL for lds, then just use the default
verbose */
/* Special case: if we got NULL for lds, then just use the default
* verbose */
if (NULL == lds) {
lds = &verbose;
}
if (NULL == lds) {
lds = &verbose;
}
/* Got a stream -- now initialize it and open relevant outputs */
/* Got a stream -- now initialize it and open relevant outputs */
info[i].ldi_used = true;
if (-1 == output_id) {
OPAL_THREAD_UNLOCK(&mutex);
}
info[i].ldi_enabled = lds->lds_is_debugging ?
(bool) OMPI_ENABLE_DEBUG : true;
info[i].ldi_verbose_level = lds->lds_verbose_level;
info[i].ldi_used = true;
if (-1 == output_id) {
OPAL_THREAD_UNLOCK(&mutex);
}
info[i].ldi_enabled = lds->lds_is_debugging ?
(bool) OMPI_ENABLE_DEBUG : true;
info[i].ldi_verbose_level = lds->lds_verbose_level;
info[i].ldi_syslog = lds->lds_want_syslog;
if (lds->lds_want_syslog) {
info[i].ldi_syslog = lds->lds_want_syslog;
if (lds->lds_want_syslog) {
#ifndef WIN32
if (NULL != lds->lds_syslog_ident) {
info[i].ldi_syslog_ident = strdup(lds->lds_syslog_ident);
openlog(lds->lds_syslog_ident, LOG_PID, LOG_USER);
} else {
info[i].ldi_syslog_ident = NULL;
openlog("opal", LOG_PID, LOG_USER);
}
if (NULL != lds->lds_syslog_ident) {
info[i].ldi_syslog_ident = strdup(lds->lds_syslog_ident);
openlog(lds->lds_syslog_ident, LOG_PID, LOG_USER);
} else {
info[i].ldi_syslog_ident = NULL;
openlog("opal", LOG_PID, LOG_USER);
}
#else
if (NULL == (info[i].ldi_syslog_ident =
RegisterEventSource(NULL, TEXT("opal: ")))) {
/* handle the error */
return OMPI_ERROR;
}
if (NULL == (info[i].ldi_syslog_ident =
RegisterEventSource(NULL, TEXT("opal: ")))) {
/* handle the error */
return OMPI_ERROR;
}
#endif
syslog_opened = true;
info[i].ldi_syslog_priority = lds->lds_syslog_priority;
}
if (NULL != lds->lds_prefix) {
info[i].ldi_prefix = strdup(lds->lds_prefix);
info[i].ldi_prefix_len = strlen(lds->lds_prefix);
} else {
info[i].ldi_prefix = NULL;
info[i].ldi_prefix_len = 0;
}
syslog_opened = true;
info[i].ldi_syslog_priority = lds->lds_syslog_priority;
}
info[i].ldi_stdout = lds->lds_want_stdout;
info[i].ldi_stderr = lds->lds_want_stderr;
if (NULL != lds->lds_prefix) {
info[i].ldi_prefix = strdup(lds->lds_prefix);
info[i].ldi_prefix_len = strlen(lds->lds_prefix);
} else {
info[i].ldi_prefix = NULL;
info[i].ldi_prefix_len = 0;
}
info[i].ldi_fd = -1;
info[i].ldi_file = lds->lds_want_file;
info[i].ldi_file_suffix = (NULL == lds->lds_file_suffix) ? NULL :
strdup(lds->lds_file_suffix);
info[i].ldi_file_want_append = lds->lds_want_file_append;
info[i].ldi_file_num_lines_lost = 0;
/* Don't open a file in the session directory now -- do that lazily
so that if there's no output, we don't have an empty file */
info[i].ldi_stdout = lds->lds_want_stdout;
info[i].ldi_stderr = lds->lds_want_stderr;
return i;
info[i].ldi_fd = -1;
info[i].ldi_file = lds->lds_want_file;
info[i].ldi_file_suffix = (NULL == lds->lds_file_suffix) ? NULL :
strdup(lds->lds_file_suffix);
info[i].ldi_file_want_append = lds->lds_want_file_append;
info[i].ldi_file_num_lines_lost = 0;
/* Don't open a file in the session directory now -- do that lazily
* so that if there's no output, we don't have an empty file */
return i;
}
@ -436,42 +442,44 @@ static int open_file(int i)
/* BWB - fix me! - used to look at orte_process_info */
dir = NULL;
if (NULL != dir) {
filename = (char*) malloc(MAXPATHLEN);
if (NULL == filename) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
strcpy(filename, dir);
strcat(filename, "/output-");
if (info[i].ldi_file_suffix != NULL) {
strcat(filename, info[i].ldi_file_suffix);
} else {
info[i].ldi_file_suffix = NULL;
strcat(filename, "output.txt");
}
flags = O_CREAT | O_RDWR;
if (!info[i].ldi_file_want_append) {
flags |= O_TRUNC;
}
filename = (char *) malloc(MAXPATHLEN);
if (NULL == filename) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
strcpy(filename, dir);
strcat(filename, "/output-");
if (info[i].ldi_file_suffix != NULL) {
strcat(filename, info[i].ldi_file_suffix);
} else {
info[i].ldi_file_suffix = NULL;
strcat(filename, "output.txt");
}
flags = O_CREAT | O_RDWR;
if (!info[i].ldi_file_want_append) {
flags |= O_TRUNC;
}
/* Actually open the file */
/* Actually open the file */
info[i].ldi_fd = open(filename, flags, 0644);
if (-1 == info[i].ldi_fd) {
info[i].ldi_used = false;
return OMPI_ERR_IN_ERRNO;
}
info[i].ldi_fd = open(filename, flags, 0644);
if (-1 == info[i].ldi_fd) {
info[i].ldi_used = false;
return OMPI_ERR_IN_ERRNO;
}
/* Make the file be close-on-exec to prevent child inheritance
* problems */
/* Make the file be close-on-exec to prevent child inheritance
problems */
#ifndef WIN32
/* TODO: Need to find out the equivalent in windows */
fcntl(info[i].ldi_fd, F_SETFD, 1);
/* TODO: Need to find out the equivalent in windows */
fcntl(info[i].ldi_fd, F_SETFD, 1);
#endif
free(filename);
free(filename);
}
/* Return successfully even if the session dir did not exist yet;
we'll try opening it later */
* we'll try opening it later */
return OMPI_SUCCESS;
}
@ -482,37 +490,36 @@ static int open_file(int i)
*/
static void free_descriptor(int output_id)
{
output_desc_t *ldi;
output_desc_t *ldi;
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS &&
info[output_id].ldi_used &&
info[output_id].ldi_enabled) {
ldi = &info[output_id];
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS &&
info[output_id].ldi_used && info[output_id].ldi_enabled) {
ldi = &info[output_id];
if (-1 != ldi->ldi_fd) {
close(ldi->ldi_fd);
}
ldi->ldi_used = false;
if (-1 != ldi->ldi_fd) {
close(ldi->ldi_fd);
}
ldi->ldi_used = false;
/* If we strduped a prefix, suffix, or syslog ident, free it */
/* If we strduped a prefix, suffix, or syslog ident, free it */
if (NULL != ldi->ldi_prefix) {
free(ldi->ldi_prefix);
}
ldi->ldi_prefix = NULL;
if (NULL != ldi->ldi_prefix) {
free(ldi->ldi_prefix);
}
ldi->ldi_prefix = NULL;
if (NULL != ldi->ldi_file_suffix) {
free(ldi->ldi_file_suffix);
}
ldi->ldi_file_suffix = NULL;
if (NULL != ldi->ldi_file_suffix) {
free(ldi->ldi_file_suffix);
}
ldi->ldi_file_suffix = NULL;
#ifndef WIN32
if (NULL != ldi->ldi_syslog_ident) {
free(ldi->ldi_syslog_ident);
}
ldi->ldi_syslog_ident = NULL;
if (NULL != ldi->ldi_syslog_ident) {
free(ldi->ldi_syslog_ident);
}
ldi->ldi_syslog_ident = NULL;
#endif
}
}
}
@ -523,102 +530,106 @@ static void free_descriptor(int output_id)
*/
static void output(int output_id, const char *format, va_list arglist)
{
size_t len, total_len;
bool want_newline = false;
char *str;
output_desc_t *ldi;
size_t len, total_len;
bool want_newline = false;
char *str;
output_desc_t *ldi;
/* Setup */
/* Setup */
if (!initialized) {
opal_output_init();
}
/* If it's valid, used, and enabled, output */
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS &&
info[output_id].ldi_used &&
info[output_id].ldi_enabled) {
ldi = &info[output_id];
/* Make the formatted string */
OPAL_THREAD_LOCK(&mutex);
vasprintf(&str, format, arglist);
total_len = len = strlen(str);
if ('\n' != str[len - 1]) {
want_newline = true;
++total_len;
}
if (NULL != ldi->ldi_prefix) {
total_len += strlen(ldi->ldi_prefix);
}
if (temp_str_len < total_len + want_newline) {
if (NULL != temp_str) {
free(temp_str);
}
temp_str = (char*) malloc(total_len * 2);
temp_str_len = total_len * 2;
}
if (NULL != ldi->ldi_prefix) {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s%s\n", ldi->ldi_prefix, str);
} else {
snprintf(temp_str, temp_str_len, "%s%s", ldi->ldi_prefix, str);
}
} else {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s\n", str);
} else {
snprintf(temp_str, temp_str_len, "%s", str);
}
if (!initialized) {
opal_output_init();
}
/* Syslog output */
/* If it's valid, used, and enabled, output */
if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS &&
info[output_id].ldi_used && info[output_id].ldi_enabled) {
ldi = &info[output_id];
/* Make the formatted string */
OPAL_THREAD_LOCK(&mutex);
vasprintf(&str, format, arglist);
total_len = len = strlen(str);
if ('\n' != str[len - 1]) {
want_newline = true;
++total_len;
}
if (NULL != ldi->ldi_prefix) {
total_len += strlen(ldi->ldi_prefix);
}
if (temp_str_len < total_len + want_newline) {
if (NULL != temp_str) {
free(temp_str);
}
temp_str = (char *) malloc(total_len * 2);
temp_str_len = total_len * 2;
}
if (NULL != ldi->ldi_prefix) {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s%s\n", ldi->ldi_prefix,
str);
} else {
snprintf(temp_str, temp_str_len, "%s%s", ldi->ldi_prefix,
str);
}
} else {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s\n", str);
} else {
snprintf(temp_str, temp_str_len, "%s", str);
}
}
/* Syslog output */
if (ldi->ldi_syslog) {
if (ldi->ldi_syslog) {
#ifndef WIN32
syslog(ldi->ldi_syslog_priority, str);
syslog(ldi->ldi_syslog_priority, str);
#endif
}
/* stdout output */
if (ldi->ldi_stdout) {
printf(temp_str);
fflush(stdout);
}
/* stderr output */
if (ldi->ldi_stderr) {
fprintf(stderr, temp_str);
fflush(stderr);
}
/* File output -- first check to see if the file opening was
* delayed. If so, try to open it. If we failed to open it,
* then just discard (there are big warnings in the
* opal_output.h docs about this!). */
if (ldi->ldi_file) {
if (ldi->ldi_fd == -1) {
if (OMPI_SUCCESS != open_file(output_id)) {
++ldi->ldi_file_num_lines_lost;
} else if (ldi->ldi_file_num_lines_lost > 0) {
char buffer[BUFSIZ];
memset(buffer, 0, BUFSIZ);
snprintf(buffer, BUFSIZ - 1,
"[WARNING: %d lines lost because the Open MPI process session directory did\n not exist when opal_output() was invoked]\n",
ldi->ldi_file_num_lines_lost);
write(ldi->ldi_fd, buffer, strlen(buffer));
ldi->ldi_file_num_lines_lost = 0;
}
}
if (ldi->ldi_fd != -1) {
write(ldi->ldi_fd, temp_str, total_len);
}
}
OPAL_THREAD_UNLOCK(&mutex);
free(str);
}
/* stdout output */
if (ldi->ldi_stdout) {
printf(temp_str);
fflush(stdout);
}
/* stderr output */
if (ldi->ldi_stderr) {
fprintf(stderr, temp_str);
fflush(stderr);
}
/* File output -- first check to see if the file opening was
delayed. If so, try to open it. If we failed to open it, then
just discard (there are big warnings in the opal_output.h docs
about this!). */
if (ldi->ldi_file) {
if (ldi->ldi_fd == -1) {
if (OMPI_SUCCESS != open_file(output_id)) {
++ldi->ldi_file_num_lines_lost;
} else if (ldi->ldi_file_num_lines_lost > 0) {
char buffer[BUFSIZ];
memset(buffer, 0, BUFSIZ);
snprintf(buffer, BUFSIZ - 1, "[WARNING: %d lines lost because the Open MPI process session directory did\n not exist when opal_output() was invoked]\n", ldi->ldi_file_num_lines_lost);
write(ldi->ldi_fd, buffer, strlen(buffer));
ldi->ldi_file_num_lines_lost = 0;
}
}
if (ldi->ldi_fd != -1) {
write(ldi->ldi_fd, temp_str, total_len);
}
}
OPAL_THREAD_UNLOCK(&mutex);
free(str);
}
}

Просмотреть файл

@ -84,306 +84,306 @@ extern "C" {
* @see output.h
*/
struct opal_output_stream_t {
/**
* Indicates whether the output of the stream is
* debugging/developer-only output or not.
*
* This field should be "true" if the output is for debugging
* purposes only. In that case, the output will never be sent to
* the stream unless OPAL was configured with --enable-debug.
*/
bool lds_is_debugging;
/**
* Indicates whether the output of the stream is
* debugging/developer-only output or not.
*
* This field should be "true" if the output is for debugging
* purposes only. In that case, the output will never be sent to
* the stream unless OPAL was configured with --enable-debug.
*/
bool lds_is_debugging;
/**
* Indicate the starting verbosity level of the stream.
*
* Verbose levels are a convenience mechanisms, and are only
* consulted when output is sent to a stream through the
* opal_output_verbose() function. Verbose levels are ignored in
* OPAL_OUTPUT() and opal_output().
*
* Valid verbose levels typically start at 0 (meaning "minimal
* information"). Higher verbosity levels generally indicate that
* more output and diagnostics should be displayed.
*/
int lds_verbose_level;
/**
* Indicates whether output of the stream should be sent to the
* syslog or not.
*
* If this field is true, output from this stream is sent to the
* syslog, and the following fields are also examined:
*
* - lds_syslog_priority
* - lds_syslog_ident
* - lds_prefix
*
* If this field is false, the above three fields are ignored.
*/
bool lds_want_syslog;
/**
* When opal_output_stream_t::lds_want_syslog is true, this field is
* examined to see what priority output from the stream should be
* sent to the syslog.
*
* This value should be set as per the syslog(3) man page. It is
* typically the OR value of "facilty" and "level" values described
* in the man page.
*/
int lds_syslog_priority;
/**
* When opal_output_stream_t::lds_want_syslog is true, this field is
* examined to see what ident value should be passed to openlog(3).
*
* If a NULL value is given, the string "opal" is used.
*/
char *lds_syslog_ident;
/**
* String prefix added to all output on the stream.
*
* When this field is non-NULL, it is prefixed to all lines of
* output on the stream. When this field is NULL, no prefix is
* added to each line of output in the stream.
*/
char *lds_prefix;
/**
* Whether to send stream output to stdout or not.
*
* If this field is true, stream output is sent to stdout.
*/
bool lds_want_stdout;
/**
* Whether to send stream output to stderr or not.
*
* If this field is true, stream output is sent to stderr.
*/
bool lds_want_stderr;
/**
* Whether to send stream output to a file or not.
*
* When this field is true, stream output is sent to a file, and the
* following fields are also examined:
*
* - lds_want_file_append
* - lda_file_suffix
*/
bool lds_want_file;
/**
* When opal_output_stream_t::lds_want_file is true, this field
* indicates whether to append the file (if it exists) or overwrite
* it.
*
* If false, the file is opened with the O_TRUNC flag.
*/
bool lds_want_file_append;
/**
* When opal_output_stream_t::lds_want_file is true, this field
* indicates the string suffix to add to the filename.
*
* The output file will be in the OPAL session directory and have a
* OPAL-generated prefix (generally "$proc_sessiondir/output-").
* The suffix is intended to give stream users a chance to write
* their output into unique files. If this field is NULL, the
* suffix "output.txt" is used.
*
* Note that it is possible that the process session directory does
* not exist when opal_output_open() is invoked. See opal_output()
* for details on what happens in this situation.
*/
char *lds_file_suffix;
/**
* Indicate the starting verbosity level of the stream.
*
* Verbose levels are a convenience mechanisms, and are only
* consulted when output is sent to a stream through the
* opal_output_verbose() function. Verbose levels are ignored in
* OPAL_OUTPUT() and opal_output().
*
* Valid verbose levels typically start at 0 (meaning "minimal
* information"). Higher verbosity levels generally indicate that
* more output and diagnostics should be displayed.
*/
int lds_verbose_level;
/**
* Indicates whether output of the stream should be sent to the
* syslog or not.
*
* If this field is true, output from this stream is sent to the
* syslog, and the following fields are also examined:
*
* - lds_syslog_priority
* - lds_syslog_ident
* - lds_prefix
*
* If this field is false, the above three fields are ignored.
*/
bool lds_want_syslog;
/**
* When opal_output_stream_t::lds_want_syslog is true, this field is
* examined to see what priority output from the stream should be
* sent to the syslog.
*
* This value should be set as per the syslog(3) man page. It is
* typically the OR value of "facilty" and "level" values described
* in the man page.
*/
int lds_syslog_priority;
/**
* When opal_output_stream_t::lds_want_syslog is true, this field is
* examined to see what ident value should be passed to openlog(3).
*
* If a NULL value is given, the string "opal" is used.
*/
char *lds_syslog_ident;
/**
* String prefix added to all output on the stream.
*
* When this field is non-NULL, it is prefixed to all lines of
* output on the stream. When this field is NULL, no prefix is
* added to each line of output in the stream.
*/
char *lds_prefix;
/**
* Whether to send stream output to stdout or not.
*
* If this field is true, stream output is sent to stdout.
*/
bool lds_want_stdout;
/**
* Whether to send stream output to stderr or not.
*
* If this field is true, stream output is sent to stderr.
*/
bool lds_want_stderr;
/**
* Whether to send stream output to a file or not.
*
* When this field is true, stream output is sent to a file, and the
* following fields are also examined:
*
* - lds_want_file_append
* - lda_file_suffix
*/
bool lds_want_file;
/**
* When opal_output_stream_t::lds_want_file is true, this field
* indicates whether to append the file (if it exists) or overwrite
* it.
*
* If false, the file is opened with the O_TRUNC flag.
*/
bool lds_want_file_append;
/**
* When opal_output_stream_t::lds_want_file is true, this field
* indicates the string suffix to add to the filename.
*
* The output file will be in the OPAL session directory and have a
* OPAL-generated prefix (generally "$proc_sessiondir/output-").
* The suffix is intended to give stream users a chance to write
* their output into unique files. If this field is NULL, the
* suffix "output.txt" is used.
*
* Note that it is possible that the process session directory does
* not exist when opal_output_open() is invoked. See opal_output()
* for details on what happens in this situation.
*/
char *lds_file_suffix;
};
typedef struct opal_output_stream_t opal_output_stream_t;
/**
* Initializes the output stream system and opens a default
* "verbose" stream.
*
* @retval true Upon success.
* @retval false Upon failure.
*
* This should be the first function invoked in the output
* subsystem. After this call, the default "verbose" stream is open
* and can be written to via calls to opal_output_verbose() and
* opal_output_error().
*
* By definition, the default verbose stream has a handle ID of 0,
* and has a verbose level of 0.
*/
OMPI_DECLSPEC bool opal_output_init(void);
/**
* Initializes the output stream system and opens a default
* "verbose" stream.
*
* @retval true Upon success.
* @retval false Upon failure.
*
* This should be the first function invoked in the output
* subsystem. After this call, the default "verbose" stream is open
* and can be written to via calls to opal_output_verbose() and
* opal_output_error().
*
* By definition, the default verbose stream has a handle ID of 0,
* and has a verbose level of 0.
*/
OMPI_DECLSPEC bool opal_output_init(void);
/**
* Shut down the output stream system.
*
* Shut down the output stream system, including the default verbose
* stream.
*/
OMPI_DECLSPEC void opal_output_finalize(void);
/**
* Shut down the output stream system.
*
* Shut down the output stream system, including the default verbose
* stream.
*/
OMPI_DECLSPEC void opal_output_finalize(void);
/**
* Opens an output stream.
*
* @param lds A pointer to opal_output_stream_t describing what the
* characteristics of the output stream should be.
*
* This function opens an output stream and returns an integer
* handle. The caller is responsible for maintaining the handle and
* using it in successive calls to OPAL_OUTPUT(), opal_output(),
* opal_output_switch(), and opal_output_close().
*
* If lds is NULL, the default descriptions will be used, meaning
* that output will only be sent to stderr.
*
* It is safe to have multiple threads invoke this function
* simultaneously; their execution will be serialized in an
* unspecified manner.
*
* Be sure to see opal_output() for a description of what happens
* when open_open() / opal_output() is directed to send output to a
* file but the process session directory does not yet exist.
*/
OMPI_DECLSPEC int opal_output_open(opal_output_stream_t *lds);
/**
* Opens an output stream.
*
* @param lds A pointer to opal_output_stream_t describing what the
* characteristics of the output stream should be.
*
* This function opens an output stream and returns an integer
* handle. The caller is responsible for maintaining the handle and
* using it in successive calls to OPAL_OUTPUT(), opal_output(),
* opal_output_switch(), and opal_output_close().
*
* If lds is NULL, the default descriptions will be used, meaning
* that output will only be sent to stderr.
*
* It is safe to have multiple threads invoke this function
* simultaneously; their execution will be serialized in an
* unspecified manner.
*
* Be sure to see opal_output() for a description of what happens
* when open_open() / opal_output() is directed to send output to a
* file but the process session directory does not yet exist.
*/
OMPI_DECLSPEC int opal_output_open(opal_output_stream_t *lds);
/**
* Re-opens / redirects an output stream.
*
* @param output_id Stream handle to reopen
* @param lds A pointer to opal_output_stream_t describing what the
* characteristics of the reopened output stream should be.
*
* This function redirects an existing stream into a new [set of]
* location[s], as specified by the lds parameter. If the output_is
* passed is invalid, this call is effectively the same as opening a
* new stream with a specific stream handle.
*/
OMPI_DECLSPEC int opal_output_reopen(int output_id, opal_output_stream_t *lds);
/**
* Enables and disables output streams.
*
* @param output_id Stream handle to switch
* @param enable Boolean indicating whether to enable the stream
* output or not.
*
* @returns The previous enable state of the stream (true == enabled,
* false == disabled).
*
* The output of a stream can be temporarily disabled by passing an
* enable value to false, and later resumed by passing an enable
* value of true. This does not close the stream -- it simply tells
* the opal_output subsystem to intercept and discard any output sent
* to the stream via OPAL_OUTPUT() or opal_output() until the output
* is re-enabled.
*/
OMPI_DECLSPEC bool opal_output_switch(int output_id, bool enable);
/**
* Re-opens / redirects an output stream.
*
* @param output_id Stream handle to reopen
* @param lds A pointer to opal_output_stream_t describing what the
* characteristics of the reopened output stream should be.
*
* This function redirects an existing stream into a new [set of]
* location[s], as specified by the lds parameter. If the output_is
* passed is invalid, this call is effectively the same as opening a
* new stream with a specific stream handle.
*/
OMPI_DECLSPEC int opal_output_reopen(int output_id, opal_output_stream_t *lds);
/**
* \internal
*
* Reopens all existing output streams.
*
* This function should never be called by user applications; it is
* typically only invoked after a restart (i.e., in a new process)
* where output streams need to be re-initialized.
*/
OMPI_DECLSPEC void opal_output_reopen_all(void);
/**
* Enables and disables output streams.
*
* @param output_id Stream handle to switch
* @param enable Boolean indicating whether to enable the stream
* output or not.
*
* @returns The previous enable state of the stream (true == enabled,
* false == disabled).
*
* The output of a stream can be temporarily disabled by passing an
* enable value to false, and later resumed by passing an enable
* value of true. This does not close the stream -- it simply tells
* the opal_output subsystem to intercept and discard any output sent
* to the stream via OPAL_OUTPUT() or opal_output() until the output
* is re-enabled.
*/
OMPI_DECLSPEC bool opal_output_switch(int output_id, bool enable);
/**
* \internal
*
* Reopens all existing output streams.
*
* This function should never be called by user applications; it is
* typically only invoked after a restart (i.e., in a new process)
* where output streams need to be re-initialized.
*/
OMPI_DECLSPEC void opal_output_reopen_all(void);
/**
* Close an output stream.
*
* @param output_id Handle of the stream to close.
*
* Close an output stream. No output will be sent to the stream
* after it is closed. Be aware that output handles tend to be
* re-used; it is possible that after a stream is closed, if another
* stream is opened, it will get the same handle value.
*/
OMPI_DECLSPEC void opal_output_close(int output_id);
/**
* Main function to send output to a stream.
*
* @param output_id Stream id returned from opal_output_open().
* @param format printf-style format string.
* @param varargs printf-style varargs list to fill the string
* specified by the format parameter.
*
* This is the main function to send output to custom streams (note
* that output to the default "verbose" stream is handled through
* opal_output_verbose() and opal_output_error()).
*
* It is never necessary to send a trailing "\n" in the strings to
* this function; some streams requires newlines, others do not --
* this function will append newlines as necessary.
*
* Verbosity levels are ignored in this function.
*
* Note that for output streams that are directed to files, the
* files are stored under the process' session directory. If the
* session directory does not exist when opal_output() is invoked,
* the output will be discarded! Once the session directory is
* created, opal_output() will automatically create the file and
* writing to it.
*/
OMPI_DECLSPEC void opal_output(int output_id, const char *format, ...);
/**
* Send output to a stream only if the passed verbosity level is
* high enough.
*
* @param output_id Stream id returned from opal_output_open().
* @param level Target verbosity level.
* @param format printf-style format string.
* @param varargs printf-style varargs list to fill the string
* specified by the format parameter.
*
* Output is only sent to the stream if the current verbosity level
* is greater than or equal to the level parameter. This mechanism
* can be used to send "information" kinds of output to user
* applications, but only when the user has asked for a high enough
* verbosity level.
*
* It is never necessary to send a trailing "\n" in the strings to
* this function; some streams requires newlines, others do not --
* this function will append newlines as necessary.
*
* This function is really a convenience wrapper around checking the
* current verbosity level set on the stream, and if the passed
* level is less than or equal to the stream's verbosity level, this
* function will effectively invoke opal_output to send the output to
* the stream.
*
* @see opal_output_set_verbosity()
*/
OMPI_DECLSPEC void opal_output_verbose(int verbose_level, int output_id,
const char *format, ...);
/**
* Set the verbosity level for a stream.
*
* @param output_id Stream id returned from opal_output_open().
* @param level New verbosity level
*
* This function sets the verbosity level on a given stream. It
* will be used for all future invocations of opal_output_verbose().
*/
OMPI_DECLSPEC void opal_output_set_verbosity(int output_id, int level);
/**
* Close an output stream.
*
* @param output_id Handle of the stream to close.
*
* Close an output stream. No output will be sent to the stream
* after it is closed. Be aware that output handles tend to be
* re-used; it is possible that after a stream is closed, if another
* stream is opened, it will get the same handle value.
*/
OMPI_DECLSPEC void opal_output_close(int output_id);
/**
* Main function to send output to a stream.
*
* @param output_id Stream id returned from opal_output_open().
* @param format printf-style format string.
* @param varargs printf-style varargs list to fill the string
* specified by the format parameter.
*
* This is the main function to send output to custom streams (note
* that output to the default "verbose" stream is handled through
* opal_output_verbose() and opal_output_error()).
*
* It is never necessary to send a trailing "\n" in the strings to
* this function; some streams requires newlines, others do not --
* this function will append newlines as necessary.
*
* Verbosity levels are ignored in this function.
*
* Note that for output streams that are directed to files, the
* files are stored under the process' session directory. If the
* session directory does not exist when opal_output() is invoked,
* the output will be discarded! Once the session directory is
* created, opal_output() will automatically create the file and
* writing to it.
*/
OMPI_DECLSPEC void opal_output(int output_id, const char *format, ...);
/**
* Send output to a stream only if the passed verbosity level is
* high enough.
*
* @param output_id Stream id returned from opal_output_open().
* @param level Target verbosity level.
* @param format printf-style format string.
* @param varargs printf-style varargs list to fill the string
* specified by the format parameter.
*
* Output is only sent to the stream if the current verbosity level
* is greater than or equal to the level parameter. This mechanism
* can be used to send "information" kinds of output to user
* applications, but only when the user has asked for a high enough
* verbosity level.
*
* It is never necessary to send a trailing "\n" in the strings to
* this function; some streams requires newlines, others do not --
* this function will append newlines as necessary.
*
* This function is really a convenience wrapper around checking the
* current verbosity level set on the stream, and if the passed
* level is less than or equal to the stream's verbosity level, this
* function will effectively invoke opal_output to send the output to
* the stream.
*
* @see opal_output_set_verbosity()
*/
OMPI_DECLSPEC void opal_output_verbose(int verbose_level, int output_id,
const char *format, ...);
/**
* Set the verbosity level for a stream.
*
* @param output_id Stream id returned from opal_output_open().
* @param level New verbosity level
*
* This function sets the verbosity level on a given stream. It
* will be used for all future invocations of opal_output_verbose().
*/
OMPI_DECLSPEC void opal_output_set_verbosity(int output_id, int level);
#if OMPI_ENABLE_DEBUG
/**
* Main macro for use in sending debugging output to output streams;
* will be "compiled out" when OPAL is configured without
* --enable-debug.
*
* @see opal_output()
*/
/**
* Main macro for use in sending debugging output to output streams;
* will be "compiled out" when OPAL is configured without
* --enable-debug.
*
* @see opal_output()
*/
#define OPAL_OUTPUT(a) opal_output a
/**
* Macro for use in sending debugging output to the output
* streams. Will be "compiled out" when OPAL is configured
@ -393,15 +393,15 @@ OMPI_DECLSPEC void opal_output_set_verbosity(int output_id, int level);
*/
#define OPAL_OUTPUT_VERBOSE(a) opal_output_verbose a
#else
/**
* Main macro for use in sending debugging output to output streams;
* will be "compiled out" when OPAL is configured without
* --enable-debug.
*
* @see opal_output()
*/
/**
* Main macro for use in sending debugging output to output streams;
* will be "compiled out" when OPAL is configured without
* --enable-debug.
*
* @see opal_output()
*/
#define OPAL_OUTPUT(a)
/**
* Macro for use in sending debugging output to the output
* streams. Will be "compiled out" when OPAL is configured