From 2ebd89d63651bf88e3acb03be0948c30396c6917 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Thu, 23 Nov 2017 20:51:33 +0100 Subject: [PATCH] Added --with-config-compat and --with-startup-compat to configure --- CHANGELOG.md | 25 ++++++++++++++------- apps/backend/backend_main.c | 18 +++++++-------- configure | 44 +++++++++++++++++++++++++++++++++++-- configure.ac | 22 +++++++++++++++++-- include/clixon_config.h.in | 9 ++++++++ include/clixon_custom.h | 6 ----- lib/src/clixon_options.c | 7 ++++++ 7 files changed, 104 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7fccfb4..86b13364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,22 +14,31 @@ SUNET for support, requests, debugging, bugfixes and proposed solutions. * Netconf client was limited to 8K byte messages. New limit is 2^32 bytes. * XML and YANG-based configuration file. - * New configuration files have .xml suffix, old have .conf. Old config files till work for backward compatibility. + * New configuration files have .xml suffix, old have .conf. * The yang model is yang/clixon-config.yang. * A migration utility is clixon_cli -x to print new format, eg: ``` -clixon_cli -f /usr/local/etc/routing.conf -1x + clixon_cli -f /usr/local/etc/routing.conf -1x ``` + * Backward compatibility is enabled: +``` + configure --with-config-compat +``` + * Both .xml and .conf works in backward compatible mode. -* Introducing backend daemon startup modes. +* Simplified backend daemon startup modes. * The flags -IRCr are replaced with command-line option -s * You use the -s to select the mode: `clixon_backend ... -s running` * You may also add a default method in the configuration file: `init` - * The option CLICON_USE_STARTUP_CONFIG is obsoleted by "startup" mode - * -I replace with -s "init" (or use of CLICON_STARTUP_MODE option) - * -CIr replace with -s "running" - * (no-option) replace with -s "none" - * Backward compatibility is enabled by defining BACKEND_STARTUP_BACKWARD_COMPAT in include/clixon_custom.h + * The configuration option CLICON_USE_STARTUP_CONFIG is obsolete + * -I replace with -s "init" (or use of CLICON_STARTUP_MODE option) + * -CIr replace with -s "running" + * (no-option) replace with -s "none" + * Backward compatibility is enabled by: +``` + configure --with-startup-compat +``` + * Both -CIr and -s works in backward compatible mode. * Extra XML has been added along with the new startup modes. Requested by Netgate. * You can add extra XML with the -c option to the backend daemon on startup: diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index 887ad08a..f65bf6c5 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -73,7 +73,7 @@ #include "backend_handle.h" /* Command line options to be passed to getopt(3) */ -#ifdef BACKEND_STARTUP_BACKWARD_COMPAT +#ifdef BACKEND_STARTUP_COMPAT #define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:IRCrg:py:x:" /* substitute s: for IRCc:r */ #else #define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:g:py:x:" /* substitute s: for IRCc:r */ @@ -142,12 +142,12 @@ usage(char *argv0, clicon_handle h) " -P \tPid filename (default: %s)\n" " -s \tSpecify backend startup mode: none|startup|running|init (replaces -IRCr\n" " -c \tLoad extra xml configuration, but don't commit.\n" -#ifdef BACKEND_STARTUP_BACKWARD_COMPAT +#ifdef BACKEND_STARTUP_COMPAT " -I\t\tInitialize running state database\n" " -R\t\tCall plugin_reset() in plugins to reset system state in running db (use with -I)\n" " -C\t\tCall plugin_reset() in plugins to reset system state in candidate db (use with -I)\n" " -r\t\tReload running database\n" -#endif /* BACKEND_STARTUP_BACKWARD_COMPAT */ +#endif /* BACKEND_STARTUP_COMPAT */ " -p \t\tPrint database yang specification\n" " -g \tClient membership required to this group (default: %s)\n" " -y \tOverride yang spec file (dont include .yang suffix)\n" @@ -271,7 +271,7 @@ plugin_start_useroptions(clicon_handle h, return 0; } -#ifdef BACKEND_STARTUP_BACKWARD_COMPAT +#ifdef BACKEND_STARTUP_COMPAT /*! Initialize running-config from file application configuration * * @param[in] h clicon handle @@ -424,7 +424,7 @@ fragmented_startup_mode(clicon_handle h, done: return retval; } -#endif /* BACKEND_STARTUP_BACKWARD_COMPAT */ +#endif /* BACKEND_STARTUP_COMPAT */ /*! Merge xml in filename into database */ @@ -599,7 +599,7 @@ main(int argc, char **argv) int foreground; int once; enum startup_mode_t startup_mode; -#ifdef BACKEND_STARTUP_BACKWARD_COMPAT +#ifdef BACKEND_STARTUP_COMPAT int init_rundb = 0; int reset_state_running = 0; int reset_state_candidate = 0; @@ -718,7 +718,7 @@ main(int argc, char **argv) case 'c': /* Load application config */ extraxml_file = optarg; break; -#ifdef BACKEND_STARTUP_BACKWARD_COMPAT +#ifdef BACKEND_STARTUP_COMPAT case 'I': /* Initiate running db */ init_rundb++; break; @@ -731,7 +731,7 @@ main(int argc, char **argv) case 'r': /* Reload running */ reload_running++; break; -#endif /* BACKEND_STARTUP_BACKWARD_COMPAT */ +#endif /* BACKEND_STARTUP_COMPAT */ case 'g': /* config socket group */ clicon_option_str_set(h, "CLICON_SOCK_GROUP", optarg); break; @@ -832,7 +832,7 @@ main(int argc, char **argv) /* If startup mode is not defined, eg via OPTION or -s, assume old method */ startup_mode = clicon_startup_mode(h); if (startup_mode == -1){ /* Old style, fragmented mode, phase out */ -#ifdef BACKEND_STARTUP_BACKWARD_COMPAT +#ifdef BACKEND_STARTUP_COMPAT if (fragmented_startup_mode(h, argv0, argc, argv, reload_running, init_rundb, diff --git a/configure b/configure index 7412f276..393e1104 100755 --- a/configure +++ b/configure @@ -632,6 +632,8 @@ CPP OBJEXT EXEEXT ac_ct_CC +with_config_compat +with_startup_compat with_keyvalue with_restconf RANLIB @@ -708,6 +710,8 @@ with_cligen with_restconf with_keyvalue with_qdbm +with_startup_compat +with_config_compat ' ac_precious_vars='build_alias host_alias @@ -1346,6 +1350,8 @@ Optional Packages: --without-restconf disable support for restconf --with-keyvalue enable support for key-value xmldb datastore --with-qdbm=dir Use QDBM here, if keyvalue + --with-startup-compat Backward compatibility of backend startup commands + --with-config-compat Backward compatibility of ocnfiguration file Some influential environment variables: CC C compiler command @@ -2341,6 +2347,8 @@ test -n "$target_alias" && # If yes, compile apps/restconf # If yes, compile datastore/keyvalue + # If yes, backward compatible backend startup + # If yes, backward compatible .conf configuration # ac_ext=c @@ -3946,9 +3954,7 @@ else with_keyvalue=no fi -echo "keyvalue:${with_keyvalue}" if test "x${with_keyvalue}" == xyes; then - echo "yes keyvalue" # This is for qdbm # Check whether --with-qdbm was given. @@ -4038,6 +4044,40 @@ fi fi +# This is for backward compatibility of backend startup commands + +# Check whether --with-startup_compat was given. +if test "${with_startup_compat+set}" = set; then : + withval=$with_startup_compat; +else + with_startup_compat=no +fi + +if test "x${with_startup_compat}" == xyes; then + +cat >>confdefs.h <<_ACEOF +#define BACKEND_STARTUP_COMPAT $with_startup_compat +_ACEOF + +fi + +# This is for backward compatibility of .conf configuration file + +# Check whether --with-config_compat was given. +if test "${with_config_compat+set}" = set; then : + withval=$with_config_compat; +else + with_config_compat=no +fi + +if test "x${with_config_compat}" == xyes; then + +cat >>confdefs.h <<_ACEOF +#define CONFIG_COMPAT $with_config_compat +_ACEOF + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypt in -lcrypt" >&5 $as_echo_n "checking for crypt in -lcrypt... " >&6; } if ${ac_cv_lib_crypt_crypt+:} false; then : diff --git a/configure.ac b/configure.ac index a5076d40..2135df41 100644 --- a/configure.ac +++ b/configure.ac @@ -80,6 +80,8 @@ AC_SUBST(AR) AC_SUBST(RANLIB) AC_SUBST(with_restconf) # If yes, compile apps/restconf AC_SUBST(with_keyvalue) # If yes, compile datastore/keyvalue +AC_SUBST(with_startup_compat) # If yes, backward compatible backend startup +AC_SUBST(with_config_compat) # If yes, backward compatible .conf configuration # AC_PROG_CC() @@ -141,9 +143,7 @@ AC_ARG_WITH([keyvalue], [AS_HELP_STRING([--with-keyvalue],[enable support for key-value xmldb datastore])], [], [with_keyvalue=no]) -echo "keyvalue:${with_keyvalue}" if test "x${with_keyvalue}" == xyes; then - echo "yes keyvalue" # This is for qdbm AC_ARG_WITH(qdbm, [ --with-qdbm=dir Use QDBM here, if keyvalue ] ) if test "${with_qdbm}"; then @@ -156,6 +156,24 @@ if test "x${with_keyvalue}" == xyes; then AC_CHECK_LIB(qdbm, dpopen,, AC_MSG_ERROR(libqdbm-dev required)) fi +# This is for backward compatibility of backend startup commands +AC_ARG_WITH([startup_compat], + [AS_HELP_STRING([--with-startup-compat],[Backward compatibility of backend startup commands])], + [], + [with_startup_compat=no]) +if test "x${with_startup_compat}" == xyes; then + AC_DEFINE_UNQUOTED(BACKEND_STARTUP_COMPAT, $with_startup_compat, [Backward compatible backend startup command-line options]) +fi + +# This is for backward compatibility of .conf configuration file +AC_ARG_WITH([config_compat], + [AS_HELP_STRING([--with-config-compat],[Backward compatibility of ocnfiguration file])], + [], + [with_config_compat=no]) +if test "x${with_config_compat}" == xyes; then + AC_DEFINE_UNQUOTED(CONFIG_COMPAT, $with_config_compat, [Backward compatible of .conf configuration files]) +fi + AC_CHECK_LIB(crypt, crypt) AC_CHECK_HEADERS(crypt.h) diff --git a/include/clixon_config.h.in b/include/clixon_config.h.in index 9840a65d..30dfb7aa 100644 --- a/include/clixon_config.h.in +++ b/include/clixon_config.h.in @@ -1,5 +1,8 @@ /* include/clixon_config.h.in. Generated from configure.ac by autoheader. */ +/* Backward compatible backend startup command-line options */ +#undef BACKEND_STARTUP_COMPAT + /* Clixon data dir for system yang files etc */ #undef CLIXON_DATADIR @@ -15,6 +18,9 @@ /* Clixon version string */ #undef CLIXON_VERSION_STRING +/* Backward compatible of .conf configuration files */ +#undef CONFIG_COMPAT + /* Define to 1 if you have the `alphasort' function. */ #undef HAVE_ALPHASORT @@ -33,6 +39,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the `cligen' library (-lcligen). */ +#undef HAVE_LIBCLIGEN + /* Define to 1 if you have the `crypt' library (-lcrypt). */ #undef HAVE_LIBCRYPT diff --git a/include/clixon_custom.h b/include/clixon_custom.h index 473ae77c..1c00ab83 100644 --- a/include/clixon_custom.h +++ b/include/clixon_custom.h @@ -48,9 +48,3 @@ int strverscmp (__const char *__s1, __const char *__s2); */ #define XML_CHILD_HASH 1 -/* Backward compatible clixon backend daemon startup sequences - * This has been replaced with -s and CLICON_STARTUP_MODE - * define if enable backward compatible behaviour - * Remove in 3.3.4 - */ -#undef BACKEND_STARTUP_BACKWARD_COMPAT diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index e8eef2c2..0f78d541 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -185,6 +185,7 @@ clicon_option_readfile_xml(clicon_hash_t *copt, return retval; } +#ifdef CONFIG_COMPAT /*! Read filename and set values to global options registry * For legacy configuration file, ie not xml @@ -344,6 +345,7 @@ clicon_option_sanity(clicon_hash_t *copt) done: return retval; } +#endif /* CONFIG_COMPAT */ /*! Initialize option values * @@ -386,6 +388,7 @@ clicon_options_main(clicon_handle h) yspec_free(yspec); } else { +#ifdef CONFIG_COMPAT /* Set default options */ if (clicon_option_default(copt) < 0) /* init registry from file */ goto done; @@ -394,6 +397,10 @@ clicon_options_main(clicon_handle h) goto done; if (clicon_option_sanity(copt) < 0) goto done; +#else /* CONFIG_COMPAT */ + clicon_err(OE_CFG, 0, "%s: suffix %s not recognized (Run ./configure --with-config-compat?)", configfile, suffix); + goto done; +#endif /* CONFIG_COMPAT */ } retval = 0; done: