Restructured error,debug anf log API
Renamed functions clicon->clixon, replaced global variables w access functions Unified clicon_netconf_error with clixon_err()
This commit is contained in:
parent
261469be16
commit
24a4991ec8
199 changed files with 4668 additions and 4158 deletions
|
|
@ -59,7 +59,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
/* clicon_cli */
|
||||
|
|
@ -87,7 +87,7 @@
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
gen_parse_tree(clicon_handle h,
|
||||
gen_parse_tree(clixon_handle h,
|
||||
char *name,
|
||||
parse_tree *pt,
|
||||
pt_head **php)
|
||||
|
|
@ -100,7 +100,7 @@ gen_parse_tree(clicon_handle h,
|
|||
if (cligen_ph_parsetree_set(ph, pt) < 0)
|
||||
goto done;
|
||||
if (cligen_ph_prompt_set(ph, CLI_DEFAULT_PROMPT) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
|
||||
clixon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
|
||||
goto done;
|
||||
}
|
||||
*php = ph;
|
||||
|
|
@ -198,7 +198,7 @@ cli_mark_output_pipes(cg_obj *co,
|
|||
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this
|
||||
*/
|
||||
static int
|
||||
clispec_load_file(clicon_handle h,
|
||||
clispec_load_file(clixon_handle h,
|
||||
const char *filename,
|
||||
const char *dir,
|
||||
parse_tree *ptall,
|
||||
|
|
@ -223,7 +223,7 @@ clispec_load_file(clicon_handle h,
|
|||
#endif
|
||||
|
||||
if ((pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
clixon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if (dir)
|
||||
|
|
@ -231,18 +231,18 @@ clispec_load_file(clicon_handle h,
|
|||
else
|
||||
snprintf(filepath, MAXPATHLEN-1, "%s", filename);
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cvec_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
/* Build parse tree from syntax spec. */
|
||||
if ((f = fopen(filepath, "r")) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "fopen %s", filepath);
|
||||
clixon_err(OE_PLUGIN, errno, "fopen %s", filepath);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Assuming this plugin is first in queue */
|
||||
if (clispec_parse_file(h, f, filepath, NULL, pt, cvv) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
|
||||
clixon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
|
||||
fclose(f);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ clispec_load_file(clicon_handle h,
|
|||
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
|
||||
handle = clixon_plugin_handle_get(cp);
|
||||
if (handle == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
|
||||
clixon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
|
||||
plgnam, filename, plgnam,
|
||||
clicon_cli_dir(h));
|
||||
goto done;
|
||||
|
|
@ -284,7 +284,7 @@ clispec_load_file(clicon_handle h,
|
|||
|
||||
/* Resolve callback names to function pointers. */
|
||||
if (cligen_callbackv_str2fn(pt, (cgv_str2fn_t*)clixon_str2fn, handle) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
|
||||
clixon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
|
||||
filename, plgnam, plgnam);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -298,7 +298,7 @@ clispec_load_file(clicon_handle h,
|
|||
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
|
||||
mode = clicon_cli_mode(h);
|
||||
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
|
||||
clicon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
|
||||
clixon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -312,7 +312,7 @@ clispec_load_file(clicon_handle h,
|
|||
* all modes may not be known (not yet loaded)
|
||||
*/
|
||||
if (cligen_parsetree_merge(ptall, NULL, pt) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -323,7 +323,7 @@ clispec_load_file(clicon_handle h,
|
|||
cg_var *cv;
|
||||
if ((ph = cligen_ph_find(cli_cligen(h), name)) == NULL){
|
||||
if ((ptnew = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
clixon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if (gen_parse_tree(h, name, ptnew, &ph) < 0)
|
||||
|
|
@ -331,12 +331,12 @@ clispec_load_file(clicon_handle h,
|
|||
if (ph == NULL)
|
||||
goto done;
|
||||
if ((cv = cv_new(CGV_STRING)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_new");
|
||||
clixon_err(OE_UNIX, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
cv_string_set(cv, name);
|
||||
if (cvec_append_var(modes, cv) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cvec_append_var");
|
||||
clixon_err(OE_UNIX, errno, "cvec_append_var");
|
||||
goto done;
|
||||
}
|
||||
if (cv)
|
||||
|
|
@ -346,12 +346,12 @@ clispec_load_file(clicon_handle h,
|
|||
if (cligen_ph_pipe_set(ph, pipetree) < 0)
|
||||
goto done;
|
||||
if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph), NULL, pt) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
goto done;
|
||||
}
|
||||
if (prompt){
|
||||
if (cligen_ph_prompt_set(ph, prompt) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
|
||||
clixon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -377,7 +377,7 @@ done:
|
|||
* XXX The parsetree loading needs a rewrite for multiple parse-trees
|
||||
*/
|
||||
int
|
||||
clispec_load(clicon_handle h)
|
||||
clispec_load(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
char *clispec_dir = NULL;
|
||||
|
|
@ -394,11 +394,11 @@ clispec_load(clicon_handle h)
|
|||
cg_var *cv = NULL;
|
||||
|
||||
if ((ptall = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
clixon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if ((modes = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
/* Format plugin directory path */
|
||||
|
|
@ -438,7 +438,7 @@ clispec_load(clicon_handle h)
|
|||
if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph),
|
||||
NULL,
|
||||
ptall) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -469,7 +469,7 @@ done:
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
int
|
||||
cli_plugin_finish(clicon_handle h)
|
||||
cli_plugin_finish(clixon_handle h)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -478,19 +478,19 @@ cli_plugin_finish(clicon_handle h)
|
|||
*
|
||||
* Sometimes the libraries specify an error string, if so print that.
|
||||
* Otherwise just print 'command error'.
|
||||
* But do not print it if error is already logged in eg clicon_err() using STDERR logging
|
||||
* But do not print it if error is already logged in eg clixon_err() using STDERR logging
|
||||
* See eg https://github.com/clicon/clixon/issues/325
|
||||
* @param[in] f File handler to write error to.
|
||||
*/
|
||||
int
|
||||
cli_handler_err(FILE *f)
|
||||
{
|
||||
if (clicon_errno){
|
||||
if (clixon_err_category()){
|
||||
/* Check if error is already logged on stderr */
|
||||
if ((clicon_get_logflags() & CLICON_LOG_STDERR) == 0){
|
||||
fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason);
|
||||
if (clicon_suberrno)
|
||||
fprintf(f, ": %s", strerror(clicon_suberrno));
|
||||
if ((clixon_get_logflags() & CLIXON_LOG_STDERR) == 0){
|
||||
fprintf(f, "%s: %s", clixon_err_str(), clixon_err_reason());
|
||||
if (clixon_err_subnr())
|
||||
fprintf(f, ": %s", strerror(clixon_err_subnr()));
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
else
|
||||
|
|
@ -517,7 +517,7 @@ cli_handler_err(FILE *f)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_parse(clicon_handle h,
|
||||
clicon_parse(clixon_handle h,
|
||||
char *cmd,
|
||||
char **modenamep,
|
||||
cligen_result *result,
|
||||
|
|
@ -535,7 +535,7 @@ clicon_parse(clicon_handle h,
|
|||
pt_head *ph;
|
||||
|
||||
ch = cli_cligen(h);
|
||||
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
|
||||
if (clixon_get_logflags()&CLIXON_LOG_STDOUT)
|
||||
f = stdout;
|
||||
else
|
||||
f = stderr;
|
||||
|
|
@ -569,10 +569,10 @@ clicon_parse(clicon_handle h,
|
|||
}
|
||||
cli_output_reset();
|
||||
if (!cligen_exiting(ch)) {
|
||||
clicon_err_reset();
|
||||
clixon_err_reset();
|
||||
if ((ret = cligen_eval(ch, match_obj, cvv)) < 0) {
|
||||
cli_handler_err(stdout);
|
||||
if (clicon_suberrno == ESHUTDOWN)
|
||||
if (clixon_err_subnr() == ESHUTDOWN)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -610,7 +610,7 @@ done:
|
|||
* @retval NULL Error
|
||||
*/
|
||||
static char *
|
||||
cli_prompt_get(clicon_handle h,
|
||||
cli_prompt_get(clixon_handle h,
|
||||
char *fmt)
|
||||
{
|
||||
char *s = fmt;
|
||||
|
|
@ -623,7 +623,7 @@ cli_prompt_get(clicon_handle h,
|
|||
char *str0;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Start with empty string */
|
||||
|
|
@ -690,7 +690,7 @@ cli_prompt_get(clicon_handle h,
|
|||
}
|
||||
str0 = cbuf_len(cb) ? cbuf_get(cb) : CLI_DEFAULT_PROMPT;
|
||||
if ((promptstr = strdup(str0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
done:
|
||||
|
|
@ -709,7 +709,7 @@ cli_prompt_get(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_cliread(clicon_handle h,
|
||||
clicon_cliread(clixon_handle h,
|
||||
pt_head *ph,
|
||||
char **stringp)
|
||||
{
|
||||
|
|
@ -739,10 +739,10 @@ clicon_cliread(clicon_handle h,
|
|||
cli_prompt_set(h, promptstr);
|
||||
free(promptstr);
|
||||
}
|
||||
clicon_err_reset();
|
||||
clixon_err_reset();
|
||||
if (cliread(cli_cligen(h), stringp) < 0){
|
||||
cli_handler_err(stdout);
|
||||
if (clicon_suberrno == ESHUTDOWN)
|
||||
if (clixon_err_subnr() == ESHUTDOWN)
|
||||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -770,7 +770,7 @@ clicon_cliread(clicon_handle h,
|
|||
* @retval 0 Not found / error
|
||||
*/
|
||||
int
|
||||
cli_set_syntax_mode(clicon_handle h,
|
||||
cli_set_syntax_mode(clixon_handle h,
|
||||
char *name)
|
||||
{
|
||||
|
||||
|
|
@ -787,7 +787,7 @@ cli_set_syntax_mode(clicon_handle h,
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
char *
|
||||
cli_syntax_mode(clicon_handle h)
|
||||
cli_syntax_mode(clixon_handle h)
|
||||
{
|
||||
pt_head *ph;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue