Change opal_err2str_fn_t to return the error string as an argument.
This means that the converters (opal_err2str, orte_err2str) can now return NULL as a "silent error". The return value of opal_err2str_fn_t is the status of the operation (OPAL_SUCCESS or OPAL_ERROR). This fixes the "Unknown error" message issues on the trunk. This commit was SVN r24371.
Этот коммит содержится в:
родитель
33b68132cc
Коммит
93d28a5792
@ -71,8 +71,8 @@ bool opal_profile = false;
|
||||
char *opal_profile_file = NULL;
|
||||
int opal_cache_line_size;
|
||||
|
||||
static const char *
|
||||
opal_err2str(int errnum)
|
||||
static int
|
||||
opal_err2str(int errnum, const char **errmsg)
|
||||
{
|
||||
const char *retval;
|
||||
|
||||
@ -205,7 +205,8 @@ opal_err2str(int errnum)
|
||||
retval = NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
*errmsg = retval;
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,16 +48,16 @@ typedef struct converter_info_t converter_info_t;
|
||||
/* all default to NULL */
|
||||
converter_info_t converters[MAX_CONVERTERS];
|
||||
|
||||
static const char *
|
||||
opal_strerror_int(int errnum)
|
||||
static int
|
||||
opal_strerror_int(int errnum, const char **str)
|
||||
{
|
||||
int i;
|
||||
const char *ret = NULL;
|
||||
int i, ret;
|
||||
*str = NULL;
|
||||
|
||||
for (i = 0 ; i < MAX_CONVERTERS ; ++i) {
|
||||
if (0 != converters[i].init) {
|
||||
ret = converters[i].converter(errnum);
|
||||
if (NULL != ret) break;
|
||||
ret = converters[i].converter(errnum, str);
|
||||
if (OPAL_SUCCESS == ret) break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,44 +66,47 @@ opal_strerror_int(int errnum)
|
||||
|
||||
|
||||
/* caller must free string */
|
||||
static char*
|
||||
opal_strerror_unknown(int errnum)
|
||||
static int
|
||||
opal_strerror_unknown(int errnum, const char **str)
|
||||
{
|
||||
int i;
|
||||
char *ret;
|
||||
*str = NULL;
|
||||
|
||||
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)",
|
||||
asprintf(str, "Unknown error: %d (%s error %d)",
|
||||
errnum, converters[i].project,
|
||||
errnum - converters[i].err_base);
|
||||
return ret;
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
asprintf(&ret, "Unknown error: %d", errnum);
|
||||
asprintf(str, "Unknown error: %d", errnum);
|
||||
|
||||
return ret;
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
opal_perror(int errnum, const char *msg)
|
||||
{
|
||||
const char* errmsg = opal_strerror_int(errnum);
|
||||
int ret;
|
||||
const char* errmsg;
|
||||
ret = opal_strerror_int(errnum, &errmsg);
|
||||
|
||||
if (NULL != msg && OPAL_SOS_GET_ERROR_CODE(errnum) != OPAL_ERR_IN_ERRNO) {
|
||||
fprintf(stderr, "%s: ", msg);
|
||||
}
|
||||
|
||||
if (NULL == errmsg) {
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
if (OPAL_SOS_GET_ERROR_CODE(errnum) == OPAL_ERR_IN_ERRNO) {
|
||||
perror(msg);
|
||||
} else {
|
||||
char *ue_msg = opal_strerror_unknown(errnum);
|
||||
const char *ue_msg;
|
||||
ret = opal_strerror_unknown(errnum, &ue_msg);
|
||||
fprintf(stderr, "%s\n", ue_msg);
|
||||
free(ue_msg);
|
||||
}
|
||||
@ -121,16 +124,18 @@ static char unknown_retbuf[UNKNOWN_RETBUF_LEN];
|
||||
const char *
|
||||
opal_strerror(int errnum)
|
||||
{
|
||||
int ret;
|
||||
const char* errmsg;
|
||||
|
||||
if (OPAL_SOS_GET_ERROR_CODE(errnum) == OPAL_ERR_IN_ERRNO) {
|
||||
return strerror(errno);
|
||||
}
|
||||
|
||||
errmsg = opal_strerror_int(errnum);
|
||||
ret = opal_strerror_int(errnum, &errmsg);
|
||||
|
||||
if (NULL == errmsg) {
|
||||
char *ue_msg = opal_strerror_unknown(errnum);
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
const char *ue_msg;
|
||||
ret = opal_strerror_unknown(errnum, &ue_msg);
|
||||
snprintf(unknown_retbuf, UNKNOWN_RETBUF_LEN, "%s", ue_msg);
|
||||
free(ue_msg);
|
||||
errno = EINVAL;
|
||||
@ -144,19 +149,21 @@ opal_strerror(int errnum)
|
||||
int
|
||||
opal_strerror_r(int errnum, char *strerrbuf, size_t buflen)
|
||||
{
|
||||
const char* errmsg = opal_strerror_int(errnum);
|
||||
int ret;
|
||||
const char* errmsg;
|
||||
int ret, len;
|
||||
|
||||
if (NULL == errmsg) {
|
||||
ret = opal_strerror_int(errnum, &errmsg);
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
if (OPAL_SOS_GET_ERROR_CODE(errnum) == OPAL_ERR_IN_ERRNO) {
|
||||
char *tmp = strerror(errno);
|
||||
strncpy(strerrbuf, tmp, buflen);
|
||||
return OPAL_SUCCESS;
|
||||
} else {
|
||||
char *ue_msg = opal_strerror_unknown(errnum);
|
||||
ret = snprintf(strerrbuf, buflen, "%s", ue_msg);
|
||||
const char *ue_msg;
|
||||
ret = opal_strerror_unknown(errnum, &ue_msg);
|
||||
len = snprintf(strerrbuf, buflen, "%s", ue_msg);
|
||||
free(ue_msg);
|
||||
if (ret > (int) buflen) {
|
||||
if (len > (int) buflen) {
|
||||
errno = ERANGE;
|
||||
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||
} else {
|
||||
@ -165,8 +172,8 @@ opal_strerror_r(int errnum, char *strerrbuf, size_t buflen)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret = snprintf(strerrbuf, buflen, "%s", errmsg);
|
||||
if (ret > (int) buflen) {
|
||||
len = snprintf(strerrbuf, buflen, "%s", errmsg);
|
||||
if (len > (int) buflen) {
|
||||
errno = ERANGE;
|
||||
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||
} else {
|
||||
|
@ -65,7 +65,7 @@ OPAL_DECLSPEC const char *opal_strerror(int errnum);
|
||||
OPAL_DECLSPEC int opal_strerror_r(int errnum, char *strerrbuf, size_t buflen);
|
||||
|
||||
|
||||
typedef const char * (*opal_err2str_fn_t)(int errnum);
|
||||
typedef int (*opal_err2str_fn_t)(int errnum, const char **str);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
|
@ -150,8 +150,8 @@ char *orte_notifier_base_peer_log(int errcode, orte_process_name_t *peer_proc,
|
||||
char *buf = (char *) malloc(ORTE_NOTIFIER_MAX_BUF + 1);
|
||||
char *peer_host = NULL, *peer_name = NULL;
|
||||
char *pos = buf;
|
||||
char *errstr = (char*)orte_err2str(errcode);
|
||||
int len, space = ORTE_NOTIFIER_MAX_BUF;
|
||||
char *errstr;
|
||||
int ret, len, space = ORTE_NOTIFIER_MAX_BUF;
|
||||
|
||||
if (NULL == buf) {
|
||||
return NULL;
|
||||
@ -173,8 +173,10 @@ char *orte_notifier_base_peer_log(int errcode, orte_process_name_t *peer_proc,
|
||||
pos += len;
|
||||
|
||||
if (0 < space) {
|
||||
if (errstr) {
|
||||
ret = orte_err2str(errcode, (const char **)&errstr);
|
||||
if (ORTE_SUCCESS == ret) {
|
||||
len = snprintf(pos, space, "'%s':", errstr);
|
||||
free(errstr);
|
||||
} else {
|
||||
len = snprintf(pos, space, "(%d):", errcode);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "orte/util/error_strings.h"
|
||||
#include "orte/runtime/orte_globals.h"
|
||||
|
||||
const char *orte_err2str(int errnum)
|
||||
int orte_err2str(int errnum, const char **errmsg)
|
||||
{
|
||||
const char *retval;
|
||||
switch (OPAL_SOS_GET_ERROR_CODE(errnum)) {
|
||||
@ -156,7 +156,8 @@ const char *orte_err2str(int errnum)
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
*errmsg = retval;
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
||||
const char *orte_job_state_to_str(orte_job_state_t state)
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
ORTE_DECLSPEC const char *orte_err2str(int errnum);
|
||||
ORTE_DECLSPEC int orte_err2str(int errnum, const char **errmsg);
|
||||
|
||||
|
||||
ORTE_DECLSPEC const char *orte_job_state_to_str(orte_job_state_t state);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user