diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 35018a68..d7e669fa 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -818,8 +818,7 @@ load_config_file(clicon_handle h, } filename = cv_string_get(cv); if (stat(filename, &st) < 0){ - clicon_err(OE_UNIX, 0, "load_config: stat(%s): %s", - filename, strerror(errno)); + clicon_err(OE_UNIX, errno, "load_config: stat(%s)", filename); goto done; } /* Open and parse local file into xml */ @@ -1338,3 +1337,4 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv) pt = cligen_ph_active_get(ch); return cligen_help(ch, stdout, pt); } + diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index 0c4cc57b..59d97ec9 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -144,7 +144,13 @@ typedef int (plgextension_t)(clicon_handle h, yang_stmt *yext, yang_stmt *ys); */ typedef int (plgauth_t)(clicon_handle, void *); -typedef int (plgreset_t)(clicon_handle h, const char *db); /* Reset system status */ +/*! Reset system status + * @param[in] h Clicon handle + * @param[in] db Database name (eg "running") + * @retval -1 Fatal error + * @retval 0 OK +*/ +typedef int (plgreset_t)(clicon_handle h, const char *db); /* Plugin statedata * @param[in] Clicon handle diff --git a/lib/src/clixon_client.c b/lib/src/clixon_client.c index c7e90ff2..79025280 100644 --- a/lib/src/clixon_client.c +++ b/lib/src/clixon_client.c @@ -240,8 +240,8 @@ clixon_client_connect(clicon_handle h, if ((netconf_bin = getenv("CLIXON_NETCONF_BIN")) == NULL) netconf_bin = CLIXON_NETCONF_BIN; if (stat(netconf_bin, &st) < 0){ - clicon_err(OE_NETCONF, 0, "netconf binary %s: %s. Set with CLIXON_NETCONF_BIN=", - netconf_bin, strerror(errno)); + clicon_err(OE_NETCONF, errno, "netconf binary %s. Set with CLIXON_NETCONF_BIN=", + netconf_bin); goto err; } argv[i++] = netconf_bin; diff --git a/lib/src/clixon_file.c b/lib/src/clixon_file.c index 7e6057b0..3e3912e9 100644 --- a/lib/src/clixon_file.c +++ b/lib/src/clixon_file.c @@ -137,7 +137,7 @@ clicon_file_dirent(const char *dir, snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dent->d_name); res = lstat(filename, &st); if (res != 0) { - clicon_err(OE_UNIX, 0, "lstat: %s", strerror(errno)); + clicon_err(OE_UNIX, errno, "lstat"); goto quit; } if ((type & st.st_mode) == 0) diff --git a/lib/src/clixon_hash.c b/lib/src/clixon_hash.c index ef7ecdc3..d08df841 100644 --- a/lib/src/clixon_hash.c +++ b/lib/src/clixon_hash.c @@ -122,7 +122,7 @@ clicon_hash_init(void) clicon_hash_t *hash; if ((hash = (clicon_hash_t *)malloc(sizeof(clicon_hash_t) * HASH_SIZE)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc: %s", strerror(errno)); + clicon_err(OE_UNIX, errno, "malloc"); return NULL; } memset(hash, 0, sizeof(clicon_hash_t)*HASH_SIZE); @@ -240,14 +240,14 @@ clicon_hash_add(clicon_hash_t *hash, h = clicon_hash_lookup(hash, key); if (h == NULL) { if ((new = (clicon_hash_t)malloc(sizeof(*new))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc: %s", strerror(errno)); + clicon_err(OE_UNIX, errno, "malloc"); goto catch; } memset(new, 0, sizeof(*new)); new->h_key = strdup(key); if (new->h_key == NULL){ - clicon_err(OE_UNIX, errno, "strdup: %s", strerror(errno)); + clicon_err(OE_UNIX, errno, "strdup"); goto catch; } @@ -258,7 +258,7 @@ clicon_hash_add(clicon_hash_t *hash, /* Make copy of value. aligned */ newval = malloc(align4(vlen+3)); if (newval == NULL){ - clicon_err(OE_UNIX, errno, "malloc: %s", strerror(errno)); + clicon_err(OE_UNIX, errno, "malloc"); goto catch; } memcpy(newval, val, vlen); @@ -349,7 +349,7 @@ clicon_hash_keys(clicon_hash_t *hash, break; tmp = realloc(keys, ((*nkeys)+1) * sizeof(char *)); if (tmp == NULL){ - clicon_err(OE_UNIX, errno, "realloc: %s", strerror(errno)); + clicon_err(OE_UNIX, errno, "realloc"); goto catch; } keys = tmp; diff --git a/lib/src/clixon_netns.c b/lib/src/clixon_netns.c index 66833e6e..d704002e 100644 --- a/lib/src/clixon_netns.c +++ b/lib/src/clixon_netns.c @@ -208,7 +208,7 @@ fork_netns_socket(const char *netns, return -1; } if (setns(fd, CLONE_NEWNET) < 0){ - clicon_err(OE_UNIX, errno, "setns(%s)%d", netns, errno); + clicon_err(OE_UNIX, errno, "setns(%s)", netns); return -1; } close(fd); diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index 2c378624..a3b0987f 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -702,7 +702,7 @@ rpc_callback_register(clicon_handle h, goto done; } if ((rc = malloc(sizeof(rpc_callback_t))) == NULL) { - clicon_err(OE_DB, errno, "malloc: %s", strerror(errno)); + clicon_err(OE_DB, errno, "malloc"); goto done; } memset(rc, 0, sizeof(*rc)); @@ -829,7 +829,7 @@ upgrade_callback_reg_fn(clicon_handle h, upgrade_callback_t *uc; if ((uc = malloc(sizeof(upgrade_callback_t))) == NULL) { - clicon_err(OE_DB, errno, "malloc: %s", strerror(errno)); + clicon_err(OE_DB, errno, "malloc"); goto done; } memset(uc, 0, sizeof(*uc)); diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index 7b5a0c57..663a697a 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -203,7 +203,6 @@ clixon_proc_socket_close(pid_t pid, * @param[out] pid * @retval 0 OK * @retval -1 Error. - * @note SIGCHLD is set to IGN here. Maybe it should be done in main? */ int clixon_proc_background(char **argv, @@ -280,9 +279,6 @@ clixon_proc_background(char **argv, done: sigprocmask(SIG_SETMASK, &oset, NULL); set_signal(SIGINT, oldhandler, NULL); - /* Ensure reap proc child in same session */ - if (set_signal(SIGCHLD, SIG_IGN, NULL) < 0) - goto quit; *pid0 = child; retval = 0; quit: diff --git a/test/lib.sh b/test/lib.sh index eb565eef..00e9eed4 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -221,7 +221,7 @@ fi # error and exit, # arg1: expected # arg2: errmsg[optional] -err(){ +function err(){ echo -e "\e[31m\nError in Test$testnr [$testname]:" if [ $# -gt 0 ]; then echo "Expected: $1" @@ -240,7 +240,7 @@ err(){ } # Test is previous test had valgrind errors if so quit -checkvalgrind(){ +function checkvalgrind(){ if [ -f $valgrindfile ]; then res=$(cat $valgrindfile | grep -e "Invalid" |awk '{print $4}' | grep -v '^0$') if [ -n "$res" ]; then @@ -260,7 +260,7 @@ checkvalgrind(){ # Start backend with all varargs. # If valgrindtest == 2, start valgrind -start_backend(){ +function start_backend(){ if [ $valgrindtest -eq 2 ]; then # Start in background since daemon version creates two traces: parent, # child. If background then only the single relevant. @@ -273,7 +273,7 @@ start_backend(){ fi } -stop_backend(){ +function stop_backend(){ sudo clixon_backend -z $* if [ $? -ne 0 ]; then err "kill backend" @@ -286,7 +286,7 @@ stop_backend(){ } # Wait for restconf to stop sending 502 Bad Gateway -wait_backend(){ +function wait_backend(){ reply=$(echo ']]>]]>' | $clixon_netconf -qef $cfg 2> /dev/null) let i=0; while [[ $reply != " /dev/null # echo "hdr:\"$hdr\"" @@ -355,7 +355,7 @@ wait_restconf(){ fi } -endtest() +function endtest() { if [ $valgrindtest -eq 1 ]; then checkvalgrind @@ -363,7 +363,7 @@ endtest() } # Increment test number and print a nice string -new(){ +function new(){ endtest # finalize previous test testnr=`expr $testnr + 1` testi=`expr $testi + 1` @@ -381,7 +381,7 @@ new(){ # Example: # expectpart "$(a-shell-cmd arg)" 0 'expected match 1' 'expected match 2' --not-- 'not expected 1' # @note need to escape \[\] -expectpart(){ +function expectpart(){ r=$? ret=$1 retval=$2 @@ -435,7 +435,7 @@ expectpart(){ # - stdin input # - expected stdout outcome # Use this if you want regex eg ^foo$ -expecteof(){ +function expecteof(){ cmd=$1 retval=$2 input=$3 @@ -482,7 +482,7 @@ EOF # - expected command return value (0 if OK) # - stdin input # - expected stdout outcome -expecteofx(){ +function expecteofx(){ cmd=$1 retval=$2 input=$3 @@ -528,7 +528,7 @@ EOF # - expected command return value (0 if OK) # - stdin input # - expected stdout outcome -expecteofeq(){ +function expecteofeq(){ cmd=$1 retval=$2 input=$3 @@ -567,7 +567,7 @@ EOF # - Command # - Filename to pipe to stdin # - expected stdout outcome -expecteof_file(){ +function expecteof_file(){ cmd=$1 retval=$2 file=$3 @@ -601,7 +601,7 @@ expecteof_file(){ # - not expected stdout outcome* # # XXX do expectwait like expectpart with multiple matches -expectwait(){ +function expectwait(){ cmd=$1 input=$2 expect=$3 @@ -632,7 +632,7 @@ expectwait(){ fi } -expectmatch(){ +function expectmatch(){ ret=$1 r=$2 expret=$3 diff --git a/test/mem.sh b/test/mem.sh index 338e6798..8171cc94 100755 --- a/test/mem.sh +++ b/test/mem.sh @@ -8,12 +8,16 @@ # Run valgrindtest once, args: # what: (cli|netconf|restconf|backend)* # no args means all -memonce(){ +function memonce(){ what=$1 valgrindfile=$(mktemp) echo "valgrindfile:$valgrindfile" + clixon_cli= + clixon_netconf= + clixon_backend= + clixon_restconf= case "$what" in 'cli') valgrindtest=1 @@ -32,7 +36,7 @@ memonce(){ clixon_backend="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --log-file=$valgrindfile clixon_backend" ;; 'restconf') - valgrindtest=3 # This means backend valgrind test + valgrindtest=3 # This means restconf valgrind test sudo chmod 660 $valgrindfile sudo chown www-data $valgrindfile : ${DEMWAIT:=15} # valgrind backend needs some time to get up @@ -66,7 +70,7 @@ memonce(){ } # Print a line with ==== under -println(){ +function println(){ str=$1 echo "$str" length=$(echo "$str" | wc -c) diff --git a/test/plot_perf.sh b/test/plot_perf.sh index 18d9a031..5a578334 100755 --- a/test/plot_perf.sh +++ b/test/plot_perf.sh @@ -89,7 +89,7 @@ EOF # Generate file with n entries # argument: -genfile(){ +function genfile(){ if [ $2 = netconf ]; then echo -n "replace" > $fxml for (( i=0; i<$1; i++ )); do @@ -114,7 +114,7 @@ genfile(){ # netconf, restconf # where op is one of: # get put delete commit -runnet(){ +function runnet(){ op=$1 nr=$2 # Number of entries in DB (keep diff from n due to shell dynamic binding) reqs=$3 @@ -165,7 +165,7 @@ done | $clixon_netconf -qf $cfg -y $fyang; } 2>&1 | awk '/real/ {print $2}' | tr # netconf, restconf # where op is one of: # get put delete -runrest(){ +function runrest(){ op=$1 nr=$2 # Number of entries in DB reqs=$3 @@ -210,12 +210,12 @@ runrest(){ } -commit(){ +function commit(){ # commit to running expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" } -reset(){ +function reset(){ # delete all in candidate expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "none]]>]]>" '^]]>]]>$' # commit to running @@ -224,7 +224,7 @@ reset(){ # Load n entries into candidate # Args: -load(){ +function load(){ # Generate file ($fxml) genfile $1 netconf # Write it to backend in one chunk @@ -236,7 +236,7 @@ load(){ # args: # =0 means all in one go # means a priori loaded into datastore -plot(){ +function plot(){ op=$1 proto=$2 from=$3 @@ -275,7 +275,7 @@ plot(){ # Each operation do times # args: # =0 means all in one go -startup(){ +function startup(){ from=$1 step=$2 to=$3 diff --git a/test/test_augment_state.sh b/test/test_augment_state.sh index 975d1ec2..210b3b9d 100755 --- a/test/test_augment_state.sh +++ b/test/test_augment_state.sh @@ -117,7 +117,7 @@ EOF # Arguments # - expected config # - expected state -testrun() +function testrun() { config=$1 state=$2 diff --git a/test/test_cli_auto_extension.sh b/test/test_cli_auto_extension.sh index 16c5b52b..6c906ed0 100755 --- a/test/test_cli_auto_extension.sh +++ b/test/test_cli_auto_extension.sh @@ -133,7 +133,7 @@ if [ $BE -ne 0 ]; then wait_backend fi -testparam() +function testparam() { # Try hidden parameter list @@ -149,7 +149,7 @@ EOF } -testvalue() +function testvalue() { # Try not hidden parameter list new "query table parameter hidden" diff --git a/test/test_cli_auto_genmodel.sh b/test/test_cli_auto_genmodel.sh index 92ba377a..ecb2cf7e 100755 --- a/test/test_cli_auto_genmodel.sh +++ b/test/test_cli_auto_genmodel.sh @@ -117,7 +117,7 @@ fi # then deleting it, and reloading it # 1. mode - either VARS Keywords on non-key variables: a y or # ALL Keywords on all variables: a x y -testrun() +function testrun() { mode=$1 if [ $mode = ALL ]; then diff --git a/test/test_datastore_repair.sh b/test/test_datastore_repair.sh index daaaa00e..c024a1f2 100755 --- a/test/test_datastore_repair.sh +++ b/test/test_datastore_repair.sh @@ -80,7 +80,7 @@ AFTER=$(cat <$2" xp=c diff --git a/test/test_nacm_credentials.sh b/test/test_nacm_credentials.sh index 88a8af73..8afef8e5 100755 --- a/test/test_nacm_credentials.sh +++ b/test/test_nacm_credentials.sh @@ -103,7 +103,7 @@ EOF # - socket family # - socket file/addr # - precommand /(eg sudo to raise to root) -testrun(){ +function testrun(){ mode=$1 username=$2 family=$3 diff --git a/test/test_nacm_datanode_read.sh b/test/test_nacm_datanode_read.sh index b933ed04..2f3283c0 100755 --- a/test/test_nacm_datanode_read.sh +++ b/test/test_nacm_datanode_read.sh @@ -164,7 +164,7 @@ EOF # - read other in same module # - read table # - read parameter -testrun(){ +function testrun(){ readdefault=$1 module=$2 table=$3 diff --git a/test/test_nacm_datanode_write.sh b/test/test_nacm_datanode_write.sh index bfae006c..918c589a 100755 --- a/test/test_nacm_datanode_write.sh +++ b/test/test_nacm_datanode_write.sh @@ -142,7 +142,7 @@ EOF # - read # - update # - delete -testrun(){ +function testrun(){ writedefault=$1 paramaccess=$2 paramaction=$3 diff --git a/test/test_nacm_default.sh b/test/test_nacm_default.sh index bc5b970c..a170897d 100755 --- a/test/test_nacm_default.sh +++ b/test/test_nacm_default.sh @@ -64,7 +64,7 @@ EOF # 6: expected return value of test2 # 7: expected return value of test3 # 8: startup mode: startup or init -testrun(){ +function testrun(){ enablenacm=$1 readdefault=$2 writedefault=$3 diff --git a/test/test_nacm_module_write.sh b/test/test_nacm_module_write.sh index 5f644248..90a7394d 100755 --- a/test/test_nacm_module_write.sh +++ b/test/test_nacm_module_write.sh @@ -161,7 +161,7 @@ if [ $RC -ne 0 ]; then fi # Set nacm from scratch -nacm(){ +function nacm(){ new "auth set authentication config" expecteof "$clixon_netconf -qf $cfg" 0 "$RULES]]>]]>" "^]]>]]>$" diff --git a/test/test_nacm_recovery.sh b/test/test_nacm_recovery.sh index 5c79ca1e..d92d8290 100755 --- a/test/test_nacm_recovery.sh +++ b/test/test_nacm_recovery.sh @@ -51,7 +51,7 @@ DEFAULT=' with pattern to test mat="$2" # expected match (1) or fail (0) str0="$3" # content string (to match against) diff --git a/test/test_perf_mem.sh b/test/test_perf_mem.sh index 568fda1c..9b805f2f 100755 --- a/test/test_perf_mem.sh +++ b/test/test_perf_mem.sh @@ -64,7 +64,7 @@ EOF # Test function # Arguments: # 1: nr size of large list -testrun(){ +function testrun(){ nr=$1 new "test params: -f $cfg" diff --git a/test/test_privileges.sh b/test/test_privileges.sh index 0e927819..d94db0b2 100755 --- a/test/test_privileges.sh +++ b/test/test_privileges.sh @@ -40,7 +40,7 @@ EOF # 3: expected user: Expected user after drop (or no drop then startuser) # 4: privileged mode (none, drop_perm, drop_temp) # 5: expect error: 0 or 1 -testrun(){ +function testrun(){ startuser=$1 beuser=$2 expectuser=$3 diff --git a/test/test_restconf.sh b/test/test_restconf.sh index d862ae74..73be3e93 100755 --- a/test/test_restconf.sh +++ b/test/test_restconf.sh @@ -106,7 +106,7 @@ fi # Restconf test routine with arguments: # 1. proto:http/https # 2: addr: 127.0.0.1/::1 # IPv4 or IPv6 -testrun() +function testrun() { proto=$1 # http/https addr=$2 # 127.0.0.1/::1 diff --git a/test/test_restconf_netns.sh b/test/test_restconf_netns.sh index 46ab49ef..4e42b17d 100755 --- a/test/test_restconf_netns.sh +++ b/test/test_restconf_netns.sh @@ -13,6 +13,11 @@ if [ "${WITH_RESTCONF}" != "evhtp" ]; then if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi +# Skip if valgrind restconf (actually valgrind version < 3.16 27 May 2020) +if [ $valgrindtest -eq 3 ]; then + if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip +fi + APPNAME=example cfg=$dir/conf.xml diff --git a/test/test_restconf_rpc.sh b/test/test_restconf_rpc.sh index b4313b94..1d5024d5 100755 --- a/test/test_restconf_rpc.sh +++ b/test/test_restconf_rpc.sh @@ -44,7 +44,7 @@ EOF # Args: # 1: operation # 2: expectret 0: means expect pi 0 as return, else something else -testrpc() +function testrpc() { operation=$1 expectret=$2 diff --git a/test/test_restconf_startup.sh b/test/test_restconf_startup.sh index 16ecab61..91f1c723 100755 --- a/test/test_restconf_startup.sh +++ b/test/test_restconf_startup.sh @@ -48,7 +48,7 @@ cat < $cfg EOF -testrun(){ +function testrun(){ option=$1 new "test params: -f $cfg -y $fyang $option" diff --git a/test/test_sock.sh b/test/test_sock.sh index cb46261e..95f42ba1 100755 --- a/test/test_sock.sh +++ b/test/test_sock.sh @@ -22,7 +22,7 @@ fyang=$dir/socket.yang # 1: UNIX|IPv4|IPv6 # 2: unix file or ipv4 address or ipv6 address # 3: session-id -testrun(){ +function testrun(){ family=$1 sock=$2 id=$3 diff --git a/test/test_ssl_certs.sh b/test/test_ssl_certs.sh index c1dcfaa0..24e0c0cb 100755 --- a/test/test_ssl_certs.sh +++ b/test/test_ssl_certs.sh @@ -156,7 +156,7 @@ cat < $cfg EOF # Run The test, ssl config is in local config -testrun() +function testrun() { cat < $dir/startup_db diff --git a/test/test_startup.sh b/test/test_startup.sh index 6d32bae0..e7a77a8e 100755 --- a/test/test_startup.sh +++ b/test/test_startup.sh @@ -61,7 +61,7 @@ brokenvar=' $cfg EOF # Start from startup and upgrade, check running -testrun(){ +function testrun(){ runxml=$1 # -u means trigger example upgrade diff --git a/test/test_upgrade_module.sh b/test/test_upgrade_module.sh index c3cf9d16..f550fdd5 100755 --- a/test/test_upgrade_module.sh +++ b/test/test_upgrade_module.sh @@ -75,7 +75,7 @@ EOF # Create 5 startup files 1-5 according to the 5 cases above (columns in the matrix) # Argument: # 1: payload, eg whats in the config apart from modstate -createstartups() +function createstartups() { payload=$1 @@ -150,7 +150,7 @@ EOF # Check statements in log # arg1: a statement to look for # arg2: expected line number -checklog(){ +function checklog(){ s=$1 # statement l0=$2 # linenr new "Check $s in log on line $l0" @@ -178,7 +178,7 @@ checklog(){ # Check statements are not in log # arg1: a statement to look for -checknolog(){ +function checknolog(){ s=$1 # statement new "Check $s not in log" # echo "grep -n "$s" $log" @@ -200,7 +200,7 @@ checknolog(){ # 2: v: verb: true or false. The next statement should be there or not # 3: what to look for in log (if v=true it should be there, if v=false it should not be there) # 4: Linenr in log -testrun(){ +function testrun(){ i=$1 flag=$2 match=$3 @@ -248,7 +248,7 @@ testrun(){ # Arguments: # 1 : payload with loaded YANG # 2 : payload without loaded YANG -testall() +function testall() { payload1=$1 payload2=$2 diff --git a/test/test_xml_trees.sh b/test/test_xml_trees.sh index 3ea8b0de..ca7ca5d6 100755 --- a/test/test_xml_trees.sh +++ b/test/test_xml_trees.sh @@ -56,7 +56,7 @@ EOF # 4: xpath # 5: retval # 6: result -testrun(){ +function testrun(){ op=$1 x0=$2 x1=$3 diff --git a/test/test_yang_anydata.sh b/test/test_yang_anydata.sh index 78b97be2..cab496d9 100755 --- a/test/test_yang_anydata.sh +++ b/test/test_yang_anydata.sh @@ -103,7 +103,7 @@ STATE1='2255a strin # Args: # 1: bool: startup (or not) # 2: bool: treat unknown as anydata (or not) -testrun() +function testrun() { startup=$1 unknown=$2 diff --git a/test/test_yang_default.sh b/test/test_yang_default.sh index fc08ad09..d4590350 100755 --- a/test/test_yang_default.sh +++ b/test/test_yang_default.sh @@ -70,7 +70,7 @@ cat < $fyang EOF # No args -testrun(){ +function testrun(){ # Initial data (default y not given) XML='0'