1
1

* Add some debugging output Ralph asked for when an unknown error code is

passed to opal_error

This commit was SVN r7087.
Этот коммит содержится в:
Brian Barrett 2005-08-29 23:36:53 +00:00
родитель d8e5d80892
Коммит 77ebdf1c6f
5 изменённых файлов: 71 добавлений и 15 удалений

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

@ -79,7 +79,7 @@ int opal_init(void)
opal_mem_free_init(); opal_mem_free_init();
/* register handler for errnum -> string converstion */ /* register handler for errnum -> string converstion */
opal_error_register(opal_err2str); opal_error_register("OPAL", OPAL_ERR_BASE, OPAL_ERR_MAX, opal_err2str);
/* initialize the mca */ /* initialize the mca */
mca_base_open(); mca_base_open();

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

@ -24,8 +24,19 @@
#include "opal/include/constants.h" #include "opal/include/constants.h"
#define MAX_CONVERTERS 5 #define MAX_CONVERTERS 5
#define MAX_CONVERTER_PROJECT_LEN 10
struct converter_info_t {
int init;
char project[MAX_CONVERTER_PROJECT_LEN];
int err_base;
int err_max;
opal_err2str_fn_t converter;
};
typedef struct converter_info_t converter_info_t;
/* all default to NULL */ /* all default to NULL */
opal_err2str_fn_t converters[MAX_CONVERTERS]; converter_info_t converters[MAX_CONVERTERS];
static const char * static const char *
opal_strerror_int(int errnum) opal_strerror_int(int errnum)
@ -34,8 +45,8 @@ opal_strerror_int(int errnum)
const char *ret = NULL; const char *ret = NULL;
for (i = 0 ; i < MAX_CONVERTERS ; ++i) { for (i = 0 ; i < MAX_CONVERTERS ; ++i) {
if (NULL != converters[i]) { if (0 != converters[i].init) {
ret = converters[i](errnum); ret = converters[i].converter(errnum);
if (NULL != ret) break; if (NULL != ret) break;
} }
} }
@ -44,6 +55,31 @@ opal_strerror_int(int errnum)
} }
/* caller must free string */
static char*
opal_strerror_unknown(int errnum)
{
int i;
char *ret;
for (i = 0 ; i < MAX_CONVERTERS ; ++i) {
if (0 != converters[i].init) {
if (errnum < converters[i].err_base &&
errnum > converters[i].err_max) {
asprintf(&ret, "Unknown error: %d (%s error %d)",
errnum, converters[i].project,
errnum - converters[i].err_base);
return ret;
}
}
}
asprintf(&ret, "Unknown error: %d", errnum);
return ret;
}
void void
opal_perror(int errnum, const char *msg) opal_perror(int errnum, const char *msg)
{ {
@ -57,7 +93,9 @@ opal_perror(int errnum, const char *msg)
if (errnum == OPAL_ERR_IN_ERRNO) { if (errnum == OPAL_ERR_IN_ERRNO) {
perror(msg); perror(msg);
} else { } else {
fprintf(stderr, "Unknown error: %d\n", errnum); char *ue_msg = opal_strerror_unknown(errnum);
fprintf(stderr, "%s\n", ue_msg);
free(ue_msg);
} }
} else { } else {
fprintf(stderr, "%s\n", errmsg); fprintf(stderr, "%s\n", errmsg);
@ -66,8 +104,9 @@ opal_perror(int errnum, const char *msg)
fflush(stderr); fflush(stderr);
} }
/* size of "Unknow error: " + 3 digits of errnumber */ /* big enough to hold long version */
static char unknown_retbuf[20]; #define UNKNOWN_RETBUF_LEN 50
static char unknown_retbuf[UNKNOWN_RETBUF_LEN];
const char * const char *
opal_strerror(int errnum) opal_strerror(int errnum)
@ -78,8 +117,10 @@ opal_strerror(int errnum)
if (errnum == OPAL_ERR_IN_ERRNO) { if (errnum == OPAL_ERR_IN_ERRNO) {
return strerror(errno); return strerror(errno);
} else { } else {
char *ue_msg = opal_strerror_unknown(errnum);
snprintf(unknown_retbuf, UNKNOWN_RETBUF_LEN, "%s", ue_msg);
free(ue_msg);
errno = EINVAL; errno = EINVAL;
snprintf(unknown_retbuf, 20, "Unknown error: %d", errnum);
return (const char*) unknown_retbuf; return (const char*) unknown_retbuf;
} }
} else { } else {
@ -100,12 +141,14 @@ opal_strerror_r(int errnum, char *strerrbuf, size_t buflen)
strncpy(strerrbuf, tmp, buflen); strncpy(strerrbuf, tmp, buflen);
return OPAL_SUCCESS; return OPAL_SUCCESS;
} else { } else {
errno = EINVAL; char *ue_msg = opal_strerror_unknown(errnum);
ret = snprintf(strerrbuf, buflen, "Unknown error: %d", errnum); ret = snprintf(strerrbuf, buflen, "%s", ue_msg);
free(ue_msg);
if (ret > (int) buflen) { if (ret > (int) buflen) {
errno = ERANGE; errno = ERANGE;
return OPAL_ERR_OUT_OF_RESOURCE; return OPAL_ERR_OUT_OF_RESOURCE;
} else { } else {
errno = EINVAL;
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
} }
@ -122,13 +165,18 @@ opal_strerror_r(int errnum, char *strerrbuf, size_t buflen)
int int
opal_error_register(opal_err2str_fn_t converter) opal_error_register(const char *project, int err_base, int err_max,
opal_err2str_fn_t converter)
{ {
int i; int i;
for (i = 0 ; i < MAX_CONVERTERS ; ++i) { for (i = 0 ; i < MAX_CONVERTERS ; ++i) {
if (NULL == converters[i]) { if (0 == converters[i].init) {
converters[i] = converter; converters[i].init = 1;
strncpy(converters[i].project, project, MAX_CONVERTER_PROJECT_LEN);
converters[i].err_base = err_base;
converters[i].err_max = err_max;
converters[i].converter = converter;
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
} }

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

@ -72,7 +72,9 @@ typedef const char * (*opal_err2str_fn_t)(int errnum);
* \note A maximum of 5 converters can be registered. The 6th * \note A maximum of 5 converters can be registered. The 6th
* converter registration attempt will return OPAL_ERR_OUT_OF_RESOURCE * converter registration attempt will return OPAL_ERR_OUT_OF_RESOURCE
*/ */
OMPI_DECLSPEC int opal_error_register(opal_err2str_fn_t converter); OMPI_DECLSPEC int opal_error_register(const char *project,
int err_base, int err_max,
opal_err2str_fn_t converter);
#if defined(c_plusplus) || defined(__cplusplus) #if defined(c_plusplus) || defined(__cplusplus)

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

@ -69,7 +69,7 @@ int orte_init_stage1(bool infrastructure)
orte_cellid_t my_cellid; orte_cellid_t my_cellid;
/* register handler for errnum -> string converstion */ /* register handler for errnum -> string converstion */
opal_error_register(orte_err2str); opal_error_register("ORTE", ORTE_ERR_BASE, ORTE_ERR_MAX, orte_err2str);
/* Register all MCA Params */ /* Register all MCA Params */
if (ORTE_SUCCESS != (ret = orte_register_params(infrastructure))) { if (ORTE_SUCCESS != (ret = orte_register_params(infrastructure))) {

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

@ -76,6 +76,12 @@ main(int argc, char *argv[])
printf("--> orte error test\n"); printf("--> orte error test\n");
opal_perror(ORTE_ERR_BUFFER, "orte test"); opal_perror(ORTE_ERR_BUFFER, "orte test");
printf("--> orte unknown error test\n");
opal_perror(ORTE_ERR_MAX + 10, "orte unknown test");
printf("--> unknown error test\n");
opal_perror(ORTE_ERR_MAX - 200, "unknown error");
orte_system_finalize(); orte_system_finalize();
opal_finalize(); opal_finalize();