From 91a583253e696f042a4a69499e61ab30f5ffdf33 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 19 Apr 2021 13:35:21 +0200 Subject: [PATCH] - Fixed plugin-module initialized twice in restconf-fcgi - Test script: wait for restconf to stop --- apps/restconf/restconf_main_fcgi.c | 3 --- lib/src/clixon_plugin.c | 8 ++++++-- test/lib.sh | 19 +++++++++++++++++++ test/test_minmax.sh | 2 +- test/test_restconf_internal.sh | 3 +++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/apps/restconf/restconf_main_fcgi.c b/apps/restconf/restconf_main_fcgi.c index a632fe42..85efdf17 100644 --- a/apps/restconf/restconf_main_fcgi.c +++ b/apps/restconf/restconf_main_fcgi.c @@ -431,9 +431,6 @@ main(int argc, if (dbg) clicon_option_dump(h, dbg); - /* Initialize plugin module by creating a handle holding plugin and callback lists */ - if (clixon_plugin_module_init(h) < 0) - goto done; /* Call start function in all plugins before we go interactive */ if (clixon_plugin_start_all(h) < 0) goto done; diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index 57c4d937..ffdfbc07 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -646,9 +646,9 @@ clixon_plugin_auth_all(clicon_handle h, clixon_auth_type_t auth_type, char **authp) { - int retval = -1; + int retval = -1; clixon_plugin_t *cp = NULL; - int ret = 0; + int ret = 0; clicon_debug(1, "%s", __FUNCTION__); if (authp == NULL){ @@ -1115,6 +1115,10 @@ clixon_plugin_module_init(clicon_handle h) int retval = -1; struct plugin_module_struct *ph; + if (plugin_module_struct_get(h) != NULL){ + clicon_err(OE_PLUGIN, EFAULT, "Already initialized"); + goto done; + } if ((ph = malloc(sizeof(*ph))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; diff --git a/test/lib.sh b/test/lib.sh index 3f3752e6..35726212 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -386,6 +386,25 @@ function wait_restconf(){ fi } +# Wait for restconf to stop +# @note assumes port=80 if RCPROTO=http and port=443 if RCPROTO=https +# @see wait_restconf +function wait_restconf_stopped(){ + hdr=$(curl $CURLOPTS $* $RCPROTO://localhost/restconf 2> /dev/null) + let i=0; + while [[ $hdr = *"200 OK"* ]]; do + if [ $i -ge $DEMLOOP ]; then + err1 "restconf timeout $DEMWAIT seconds" + fi + sleep $DEMSLEEP + hdr=$(curl $CURLOPTS $* $RCPROTO://localhost/restconf 2> /dev/null) + let i++; + done + if [ $valgrindtest -eq 3 ]; then + sleep 2 # some problems with valgrind + fi +} + # End of test, final tests before normal exit of test function endtest() { diff --git a/test/test_minmax.sh b/test/test_minmax.sh index 83e393bb..c9aec8b7 100755 --- a/test/test_minmax.sh +++ b/test/test_minmax.sh @@ -245,7 +245,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO new "minmax: validate should fail empty list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^protocoloperation-failedtoo-few-elementserror/c/a1]]>]]>$" -if [ $BE -ne 0]; then +if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) diff --git a/test/test_restconf_internal.sh b/test/test_restconf_internal.sh index ba53e94a..987a223a 100755 --- a/test/test_restconf_internal.sh +++ b/test/test_restconf_internal.sh @@ -223,6 +223,9 @@ new "4. stop restconf RPC" rpcoperation stop if [ $? -ne 0 ]; then exit -1; fi +new "Wait for restrconf to stop" +wait_restconf_stopped + new "5. Get rpc status stopped" rpcstatus false stopped if [ $pid -ne 0 ]; then err "Pid" "$pid"; fi