Replaced the global variable debug with access function: clicon_debug_get().

This commit is contained in:
Olof hagsand 2020-06-09 16:04:49 +02:00
parent 718f494549
commit ff5462ecac
35 changed files with 227 additions and 100 deletions

View file

@ -118,6 +118,7 @@ main(int argc, char **argv)
int i;
char *xpath;
cbuf *cbret = NULL;
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
@ -135,7 +136,7 @@ main(int argc, char **argv)
usage(argv0);
break;
case 'D' : /* debug */
debug = 1;
dbg = 1;
break;
case 'd': /* db symbolic: running|candidate|startup */
if (!optarg)
@ -166,8 +167,8 @@ main(int argc, char **argv)
/*
* Logs, error and debug to stderr, set debug level
*/
clicon_log_init(__FILE__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clicon_debug_init(debug, NULL);
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clicon_debug_init(dbg, NULL);
argc -= optind;
argv += optind;

View file

@ -96,6 +96,7 @@ main(int argc,
cxobj *xerr = NULL; /* malloced must be freed */
int ret;
int pretty = 0;
int dbg = 0;
optind = 1;
opterr = 0;
@ -105,7 +106,7 @@ main(int argc,
usage(argv[0]);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv[0]);
break;
case 'j':
@ -125,7 +126,9 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_log_init(__FILE__, debug?LOG_DEBUG:LOG_INFO, logdst);
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
if (yang_filename){
if ((yspec = yspec_new()) == NULL)
goto done;

View file

@ -109,6 +109,7 @@ main(int argc,
cxobj *xcfg = NULL;
cxobj *xerr = NULL; /* malloced must be freed */
int nr = 1;
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init("api-path", LOG_DEBUG, CLICON_LOG_STDERR);
@ -129,7 +130,7 @@ main(int argc,
usage(argv0);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv0);
break;
case 'f': /* XML file */
@ -159,6 +160,8 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_debug_init(dbg, NULL);
/* Parse yang */
if (yang_file_dir){
if ((yspec = yspec_new()) == NULL)

View file

@ -163,6 +163,7 @@ main(int argc,
int ret = 0;
int nr = 1;
int mode = 0; /* 0 is posix, 1 is libxml */
int dbg = 0;
optind = 1;
opterr = 0;
@ -172,7 +173,7 @@ main(int argc,
usage(argv0);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv0);
break;
case 'p': /* xsd->posix */
@ -195,7 +196,9 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_log_init(__FILE__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clicon_debug_init(dbg, NULL);
if (regexp == NULL){
fprintf(stderr, "-r mandatory\n");
usage(argv0);
@ -211,12 +214,12 @@ main(int argc,
clicon_debug(1, "regexp:%s", regexp);
clicon_debug(1, "content:%s", content);
if (mode == 0){
if ((ret = regex_posix(regexp, content, nr, debug)) < 0)
if ((ret = regex_posix(regexp, content, nr, dbg)) < 0)
goto done;
}
else if (mode == 1){
if ((ret = regex_libxml2(regexp, content, nr, debug)) < 0)
if ((ret = regex_libxml2(regexp, content, nr, dbg)) < 0)
goto done;
}
else

View file

@ -95,6 +95,7 @@ main(int argc,
int ret;
cbuf *cb = cbuf_new();
clicon_handle h;
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
@ -110,7 +111,7 @@ main(int argc,
usage(argv[0]);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv[0]);
break;
case 's':
@ -129,7 +130,9 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_log_init(__FILE__, debug?LOG_DEBUG:LOG_INFO, logdst);
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
if (sockpath == NULL){
fprintf(stderr, "Mandatory option missing: -s <sockpath>\n");
usage(argv[0]);

View file

@ -219,6 +219,7 @@ main(int argc, char **argv)
int c;
char *argv0 = argv[0];
struct timeval now;
int dbg = 0;
clicon_log_init("xpath", LOG_DEBUG, CLICON_LOG_STDERR);
gettimeofday(&now, NULL);
@ -230,7 +231,7 @@ main(int argc, char **argv)
usage(argv0);
break;
case 'D':
debug++;
dbg = 1;
break;
case 'u': /* URL */
url = optarg;
@ -264,6 +265,7 @@ main(int argc, char **argv)
usage(argv[0]);
break;
}
clicon_debug_init(dbg, NULL);
if (url == NULL)
usage(argv[0]);
curl_global_init(0);

View file

@ -163,6 +163,7 @@ main(int argc,
cxobj *xbot; /* Place in xtop where base cxobj is parsed */
cvec *nsc = NULL;
yang_bind yb;
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
@ -184,7 +185,7 @@ main(int argc,
usage(argv[0]);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv[0]);
break;
case 'f':
@ -239,7 +240,9 @@ main(int argc,
fprintf(stderr, "-t requires -T\n");
usage(argv[0]);
}
clicon_log_init(__FILE__, debug?LOG_DEBUG:LOG_INFO, logdst);
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
/* 1. Parse yang */
if (yang_file_dir){
if ((yspec = yspec_new()) == NULL)
@ -319,7 +322,7 @@ main(int argc,
}
/* Dump data structures (for debug) */
if (debug){
if (clicon_debug_get()){
cbuf_reset(cb);
xmltree2cbuf(cb, xt, 0);
fprintf(stderr, "%s\n", cbuf_get(cb));

View file

@ -129,6 +129,7 @@ main(int argc, char **argv)
clicon_handle h;
enum opx opx = OPX_ERROR;
char *reason = NULL;
int dbg = 0;
clicon_log_init("clixon_insert", LOG_DEBUG, CLICON_LOG_STDERR);
if ((h = clicon_handle_init()) == NULL)
@ -141,7 +142,7 @@ main(int argc, char **argv)
usage(argv0);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv0);
break;
case 'o': /* Operation */
@ -171,6 +172,7 @@ main(int argc, char **argv)
usage(argv0);
if (opx == OPX_ERROR)
usage(argv0);
clicon_debug_init(dbg, NULL);
if ((yspec = yspec_new()) == NULL)
goto done;
if (yang_spec_parse_file(h, yangfile, yspec) < 0)
@ -189,7 +191,7 @@ main(int argc, char **argv)
clicon_err(OE_XML, 0, "xpath: %s not found in x0", xpath);
goto done;
}
if (debug){
if (clicon_debug_get()){
clicon_debug(1, "xb:");
xml_print(stderr, xb);
}
@ -256,7 +258,7 @@ main(int argc, char **argv)
default:
usage(argv0);
}
if (debug){
if (clicon_debug_get()){
clicon_debug(1, "x0:");
xml_print(stderr, x0);
}

View file

@ -140,6 +140,7 @@ main(int argc,
cxobj *xcfg = NULL;
cbuf *cbret = NULL;
cxobj *xerr = NULL; /* malloced must be freed */
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init("xpath", LOG_DEBUG, CLICON_LOG_STDERR);
@ -160,7 +161,7 @@ main(int argc,
usage(argv0);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv0);
break;
case 'f': /* XML file */
@ -210,6 +211,8 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_debug_init(dbg, NULL);
/* Parse yang */
if (yang_file_dir){
if ((yspec = yspec_new()) == NULL)

View file

@ -81,6 +81,7 @@ main(int argc, char **argv)
yang_stmt *yspec = NULL;
int c;
int logdst = CLICON_LOG_STDERR;
int dbg = 0;
optind = 1;
opterr = 0;
@ -90,7 +91,7 @@ main(int argc, char **argv)
usage(argv[0]);
break;
case 'D':
if (sscanf(optarg, "%d", &debug) != 1)
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv[0]);
break;
case 'l': /* Log destination: s|e|o|f */
@ -101,7 +102,8 @@ main(int argc, char **argv)
usage(argv[0]);
break;
}
clicon_log_init("clixon_util_yang", debug?LOG_DEBUG:LOG_INFO, logdst);
clicon_log_init("clixon_util_yang", dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
if ((yspec = yspec_new()) == NULL)
goto done;
if (yang_parse_file(0, "yang test", yspec) == NULL){