Enable calling clicon_err_fn with fn=NULL

This commit is contained in:
Olof hagsand 2022-07-22 18:36:53 +02:00
parent aaa18897ef
commit f9eacebf68

View file

@ -239,30 +239,48 @@ clicon_err_fn(const char *fn,
if (cec->cec_logfn(cec->cec_handle, suberr, cb) < 0) if (cec->cec_logfn(cec->cec_handle, suberr, cb) < 0)
goto done; goto done;
/* Here we could take care of specific errno, like application-defined errors */ /* Here we could take care of specific errno, like application-defined errors */
if (fn)
clicon_log(LOG_ERR, "%s: %d: %s: %s: %s", clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
fn, fn,
line, line,
clicon_strerror(category), clicon_strerror(category),
cbuf_get(cb), cbuf_get(cb),
msg); msg);
else
clicon_log(LOG_ERR, "%s: %s: %s",
clicon_strerror(category),
cbuf_get(cb),
msg);
if (cb) if (cb)
cbuf_free(cb); cbuf_free(cb);
} }
else if (suberr){ /* Actually log it */ else if (suberr){ /* Actually log it */
/* Here we could take care of specific errno, like application-defined errors */ /* Here we could take care of specific errno, like application-defined errors */
if (fn)
clicon_log(LOG_ERR, "%s: %d: %s: %s: %s", clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
fn, fn,
line, line,
clicon_strerror(category), clicon_strerror(category),
msg, msg,
suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr)); suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
}
else else
clicon_log(LOG_ERR, "%s: %s: %s",
clicon_strerror(category),
msg,
suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
}
else{
if (fn)
clicon_log(LOG_ERR, "%s: %d: %s: %s", clicon_log(LOG_ERR, "%s: %d: %s: %s",
fn, fn,
line, line,
clicon_strerror(category), clicon_strerror(category),
msg); msg);
else
clicon_log(LOG_ERR, "%s: %s",
clicon_strerror(category),
msg);
}
retval = 0; retval = 0;
done: done:
if (msg) if (msg)