Changed ca_errmsg callback to a more generic variant

Includes all error, log and debug messages
See [Customized NETCONF error message](https://github.com/clicon/clixon/issues/454)
This commit is contained in:
Olof hagsand 2023-12-22 22:27:54 +01:00
parent 798a9fbfcb
commit 9e54f0602f
83 changed files with 739 additions and 616 deletions

View file

@ -462,13 +462,7 @@ cli_dbxml(clixon_handle h,
if ((ret = api_path2xml(api_path, yspec0, xtop, YC_DATANODE, 1, &xbot, &y, &xerr)) < 0)
goto done;
if (ret == 0){
if ((cb = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (netconf_err2cb(h, xerr, cb) < 0)
goto done;
clixon_err(OE_CFG, EINVAL, "api-path syntax error \"%s\": %s", api_path_fmt, cbuf_get(cb));
clixon_err_netconf(h, OE_CFG, EINVAL, xerr, "api-path syntax error \"%s\"", api_path_fmt);
goto done;
}
}

View file

@ -488,7 +488,9 @@ cli_handler_err(FILE *f)
if (clixon_err_category()){
/* Check if error is already logged on stderr */
if ((clixon_get_logflags() & CLIXON_LOG_STDERR) == 0){
fprintf(f, "%s: %s", clixon_err_str(), clixon_err_reason());
if (clixon_err_category() != -1)
fprintf(f, "%s: ", clixon_err_str());
fprintf(f, "%s", clixon_err_reason());
if (clixon_err_subnr())
fprintf(f, ": %s", strerror(clixon_err_subnr()));
fprintf(f, "\n");

View file

@ -713,7 +713,7 @@ main(int argc,
if (sscanf(optarg, "%d", &dbg) != 1)
usage(h, argv[0]);
break;
case 'f': /* override config file */
case 'f': /* override config file */
if (!strlen(optarg))
usage(h, argv[0]);
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
@ -723,14 +723,14 @@ main(int argc,
usage(h, argv[0]);
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break;
case 'l': /* Log destination: s|e|o */
case 'l': /* Log destination: s|e|o */
if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]);
if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 &&
clixon_log_file(optarg+1) < 0)
goto done;
break;
break;
}
/*
@ -889,7 +889,7 @@ main(int argc,
/* Load clixon lib yang module */
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
goto done;
/* Load yang module library, RFC7895 */
/* Load yang module library, RFC7895 */
if (yang_modules_init(h) < 0)
goto done;
/* Add netconf yang spec, used by netconf client and as internal protocol */
@ -935,7 +935,7 @@ main(int argc,
}
#ifdef __AFL_HAVE_MANUAL_CONTROL
/* American fuzzy loop deferred init, see CLICON_NETCONF_HELLO_OPTIONAL=true, see a speedup of x10 */
__AFL_INIT();
__AFL_INIT();
#endif
if (clixon_event_reg_fd(0, netconf_input_cb, h, "netconf socket") < 0)
goto done;
@ -950,12 +950,12 @@ main(int argc,
goto done;
ok:
retval = 0;
done:
done:
if (ignore_packet_errors)
retval = 0;
clixon_exit_set(1); /* This is to disable resend mechanism in close-session */
netconf_terminate(h);
clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
netconf_terminate(h);
return retval;
}

View file

@ -353,17 +353,17 @@ api_return_err(clixon_handle h,
* @see api_return_err where top level is expected to be <rpc-error>
*/
int
api_return_err0(clixon_handle h,
void *req,
cxobj *xerr,
int pretty,
api_return_err0(clixon_handle h,
void *req,
cxobj *xerr,
int pretty,
restconf_media media,
int code)
int code)
{
int retval = -1;
cxobj *xe;
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
if ((xe = xml_find_type(xerr, NULL, "rpc-error", CX_ELMNT)) == NULL){
clixon_err(OE_XML, EINVAL, "Expected xml on the form <rpc-error>..");
goto done;
}