diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index 7895fb45..49658907 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -1004,7 +1004,7 @@ main(int argc, goto done; /* Write pid-file */ - if ((pid = pidfile_write(pidfile)) < 0) + if (pidfile_write(pidfile) < 0) goto done; if (set_signal(SIGTERM, backend_sig_term, NULL) < 0){ diff --git a/apps/snmp/snmp_main.c b/apps/snmp/snmp_main.c index c2e25e5e..c9599d1f 100644 --- a/apps/snmp/snmp_main.c +++ b/apps/snmp/snmp_main.c @@ -60,6 +60,14 @@ /* Command line options to be passed to getopt(3) */ #define SNMP_OPTS "hD:f:l:o:" +/*! Return (hardcoded) pid file + */ +static char* +clicon_snmp_pidfile(clicon_handle h) +{ + return "/var/tmp/clixon_snmp.pid"; +} + /*! Signal terminates process * Just set exit flag for proper exit in event loop */ @@ -197,6 +205,7 @@ snmp_terminate(clicon_handle h) yang_stmt *yspec; cvec *nsctx; cxobj *x; + char *pidfile = clicon_snmp_pidfile(h); shutdown_agent(); clicon_rpc_close_session(h); @@ -213,6 +222,8 @@ snmp_terminate(clicon_handle h) clicon_handle_exit(h); clixon_err_exit(); clicon_log_exit(); + if (pidfile) + unlink(pidfile); return 0; } @@ -254,6 +265,7 @@ main(int argc, size_t cligen_bufthreshold; int dbg = 0; size_t sz; + char *pidfile = NULL; /* Create handle */ if ((h = clicon_handle_init()) == NULL) @@ -415,6 +427,14 @@ main(int argc, if (dbg) clicon_option_dump(h, dbg); + /* Check pid-file, if zap kil the old daemon, else return here */ + if ((pidfile = clicon_snmp_pidfile(h)) == NULL){ + clicon_err(OE_FATAL, 0, "pidfile not set"); + goto done; + } + /* Write pid-file */ + if (pidfile_write(pidfile) < 0) + goto done; /* main event loop */ if (clixon_event_loop(h) < 0) goto done; diff --git a/apps/snmp/snmp_mib_yang.c b/apps/snmp/snmp_mib_yang.c index 4141ca3d..d79e40d0 100644 --- a/apps/snmp/snmp_mib_yang.c +++ b/apps/snmp/snmp_mib_yang.c @@ -214,7 +214,7 @@ snmp_table_handler(netsnmp_mib_handler *handler, } ok: retval = SNMP_ERR_NOERROR; -done: + //done: if (xt) xml_free(xt); if (cb) @@ -254,10 +254,7 @@ snmp_scalar_handler(netsnmp_mib_handler *handler, u_char *snmpval = NULL; size_t snmplen; int ret; -<<<<<<< HEAD -======= netsnmp_variable_list *requestvb; /* sub of requests */ ->>>>>>> SNMP frontend: getnext, oid sanity checks and scalar debug /* * can be used to pass information on a per-pdu basis from a diff --git a/test/lib.sh b/test/lib.sh index d1157031..0cf62033 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -187,6 +187,8 @@ BUSER=clicon : ${clixon_snmp:=$(type -p clixon_snmp)} +: ${clixon_snmp_pidfile:="/var/tmp/clixon_snmp.pid"} + # Source the site-specific definitions for test script variables, if site.sh # exists. The variables defined in site.sh override any variables of the same # names in the environment in the current execution. @@ -447,6 +449,8 @@ function chunked_framing() function start_snmp(){ cfg=$1 + rm -f ${clixon_snmp_pidfile} + $clixon_snmp -f $cfg -D $DBG & if [ $? -ne 0 ]; then @@ -465,6 +469,7 @@ function stop_snmp(){ else killall -q clixon_snmp fi + rm -f ${clixon_snmp_pidfile} } # Start backend with all varargs. @@ -601,7 +606,14 @@ function wait_restconf_stopped(){ # need a better way to detect liveness of clixon_snmp function wait_snmp() { - sleep 3 + let i=0; + while [ ! -f ${clixon_snmp_pidfile} ]; do + if [ $i -ge $DEMLOOP ]; then + err1 "snmp timeout $DEMWAIT seconds" + fi + sleep $DEMSLEEP + let i++; + done } # End of test, final tests before normal exit of test diff --git a/test/test_snmp.sh b/test/test_snmp.sh index e1c565d9..75f4b7da 100755 --- a/test/test_snmp.sh +++ b/test/test_snmp.sh @@ -108,7 +108,6 @@ MIB=".1.3.6.1.4.1.8072.2" OID1="${MIB}.1.1" # netSnmpExampleInteger OID2="${MIB}.1.2" # netSnmpExampleSleeper OID3="${MIB}.1.3" # netSnmpExampleString -OID4="${MIB}.3.2.1" # netSnmpExampleHeartbeatRate new "$snmpget"