From 08b128f4d7f79ae44380233f32ec06ed25cedc2d Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 1 Dec 2019 17:42:34 +0100 Subject: [PATCH] moved config yang spec from main functions to options_main function --- apps/backend/backend_main.c | 9 +-------- apps/cli/cli_main.c | 10 ++-------- apps/netconf/netconf_main.c | 12 +++--------- apps/restconf/restconf_main.c | 8 +------- lib/clixon/clixon_options.h | 2 +- lib/src/clixon_options.c | 13 ++++++++++--- 6 files changed, 18 insertions(+), 36 deletions(-) diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index da6c2f14..b1091f3d 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -446,7 +446,6 @@ main(int argc, char *nacm_mode; int logdst = CLICON_LOG_SYSLOG|CLICON_LOG_STDERR; yang_stmt *yspec = NULL; - yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ char *str; int ss = -1; /* server socket */ cbuf *cbret = NULL; /* startup cbuf if invalid */ @@ -509,18 +508,12 @@ main(int argc, clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, logdst); clicon_debug_init(debug, NULL); - /* Create configure yang-spec (note different from dbspec holding application specs) */ - if ((yspecfg = yspec_new()) == NULL) - goto done; - /* Find and read configfile */ - if (clicon_options_main(h, yspecfg) < 0){ + if (clicon_options_main(h) < 0){ if (help) usage(h, argv[0]); return -1; } - if (clicon_config_yang_set(h, yspecfg) < 0) - goto done; /* External NACM file? */ nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE"); diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 172fc8d0..cc5de600 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -283,7 +283,6 @@ main(int argc, char **argv) int logdst = CLICON_LOG_STDERR; char *restarg = NULL; /* what remains after options */ yang_stmt *yspec; - yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ struct passwd *pw; char *str; int tabmode; @@ -352,17 +351,12 @@ main(int argc, char **argv) clicon_debug_init(debug, NULL); - /* Create configure yang-spec (note different from dbspec holding application specs) */ - if ((yspecfg = yspec_new()) == NULL) - goto done; - /* Find and read configfile */ - if (clicon_options_main(h, yspecfg) < 0){ + /* Find, read and parse configfile */ + if (clicon_options_main(h) < 0){ if (help) usage(h, argv[0]); return -1; } - if (clicon_config_yang_set(h, yspecfg) < 0) - goto done; /* Now rest of options */ opterr = 0; diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c index b3d8b215..b98028a5 100644 --- a/apps/netconf/netconf_main.c +++ b/apps/netconf/netconf_main.c @@ -395,7 +395,6 @@ main(int argc, struct passwd *pw; struct timeval tv = {0,}; /* timeout */ yang_stmt *yspec = NULL; - yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ char *str; uint32_t id; cvec *nsctx_global = NULL; /* Global namespace context */ @@ -443,15 +442,10 @@ main(int argc, clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, logdst); clicon_debug_init(debug, NULL); - /* Create configure yang-spec (note different from dbspec holding application specs) */ - if ((yspecfg = yspec_new()) == NULL) - goto done; - /* Find and read configfile */ - if (clicon_options_main(h, yspecfg) < 0) + /* Find, read and parse configfile */ + if (clicon_options_main(h) < 0) return -1; - if (clicon_config_yang_set(h, yspecfg) < 0) - goto done; - + /* Now rest of options */ optind = 1; opterr = 0; diff --git a/apps/restconf/restconf_main.c b/apps/restconf/restconf_main.c index aaa639be..e9354b18 100644 --- a/apps/restconf/restconf_main.c +++ b/apps/restconf/restconf_main.c @@ -582,7 +582,6 @@ main(int argc, char *dir; int logdst = CLICON_LOG_SYSLOG; yang_stmt *yspec = NULL; - yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ char *stream_path; int finish = 0; int start = 1; @@ -642,13 +641,8 @@ main(int argc, goto done; } - /* Create configure yang-spec note different from dbspec holding application specs) */ - if ((yspecfg = yspec_new()) == NULL) - goto done; /* Find and read configfile */ - if (clicon_options_main(h, yspecfg) < 0) - goto done; - if (clicon_config_yang_set(h, yspecfg) < 0) + if (clicon_options_main(h) < 0) goto done; stream_path = clicon_option_str(h, "CLICON_STREAM_PATH"); diff --git a/lib/clixon/clixon_options.h b/lib/clixon/clixon_options.h index 6177ee71..51eaedc7 100644 --- a/lib/clixon/clixon_options.h +++ b/lib/clixon/clixon_options.h @@ -109,7 +109,7 @@ int clicon_option_dump(clicon_handle h, int dblevel); int clicon_option_add(clicon_handle h, char *name, char *value); /* Initialize options: set defaults, read config-file, etc */ -int clicon_options_main(clicon_handle h, yang_stmt *yspec); +int clicon_options_main(clicon_handle h); /*! Check if a clicon option has a value */ int clicon_option_exists(clicon_handle h, const char *name); diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index 72feb443..5b53cfc6 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -355,8 +355,7 @@ clicon_option_add(clicon_handle h, * other yang modules. */ int -clicon_options_main(clicon_handle h, - yang_stmt *yspec) +clicon_options_main(clicon_handle h) { int retval = -1; char *configfile; @@ -364,7 +363,11 @@ clicon_options_main(clicon_handle h, char *suffix; char xml = 0; /* Configfile is xml, otherwise legacy */ cxobj *xconfig = NULL; + yang_stmt *yspec = NULL; + /* Create configure yang-spec */ + if ((yspec = yspec_new()) == NULL) + goto done; /* * Set configure file if not set by command-line above */ @@ -413,8 +416,12 @@ clicon_options_main(clicon_handle h, clicon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: or clixon-config.yang not found?", configfile, CLIXON_CONF_NS); goto done; } + /* Set yang config spec (must store to free at exit, since conf_xml below uses it) */ + if (clicon_config_yang_set(h, yspec) < 0) + goto done; /* Set clixon_conf pointer to handle */ - clicon_conf_xml_set(h, xconfig); + if (clicon_conf_xml_set(h, xconfig) < 0) + goto done; retval = 0; done: