diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 6845696c5..a952bbbed 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -1860,7 +1860,7 @@ from_client(int s, } if (ce_client_descr(ce, &cbce) < 0) goto done; - if (clixon_msg_rcv11(s, NULL, &cb, &eof) < 0) + if (clixon_msg_rcv11(s, NULL, 0, &cb, &eof) < 0) goto done; if (eof){ backend_client_rm(h, ce); diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index a0159d68a..e8fb157f6 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -1408,7 +1408,7 @@ cli_notification_cb(int s, enum format_enum format = (enum format_enum)(uintptr_t)arg; cbuf *cb = NULL; - if (clixon_msg_rcv11(s, NULL, &cb, &eof) < 0) + if (clixon_msg_rcv11(s, NULL, 0, &cb, &eof) < 0) goto done; if (eof){ clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index d9e01e877..58a454b5d 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -461,7 +461,7 @@ netconf_notification_cb(int s, clixon_debug(CLIXON_DBG_NETCONF, ""); yspec = clicon_dbspec_yang(h); - if (clixon_msg_rcv11(s, NULL, &cbmsg, &eof) < 0) + if (clixon_msg_rcv11(s, NULL, 0, &cbmsg, &eof) < 0) goto done; /* handle close from remote end: this will exit the client */ if (eof){ diff --git a/apps/restconf/restconf_stream_fcgi.c b/apps/restconf/restconf_stream_fcgi.c index f2af65c7d..58c2aa365 100644 --- a/apps/restconf/restconf_stream_fcgi.c +++ b/apps/restconf/restconf_stream_fcgi.c @@ -211,14 +211,13 @@ restconf_stream_cb(int s, cxobj *xtop = NULL; /* top xml */ cxobj *xn; /* notification xml */ cbuf *cb = NULL; - int pretty = 0; /* XXX should be via arg */ cbuf *cbmsg = NULL; + int pretty = 0; /* XXX should be via arg */ int ret; clixon_debug(CLIXON_DBG_STREAM, ""); - if (clixon_msg_rcv11(s, NULL, &cbmsg, &eof) < 0) + if (clixon_msg_rcv11(s, NULL, 0, &cbmsg, &eof) < 0) goto done; - clixon_debug(CLIXON_DBG_STREAM, "msg: %s", reply?reply->op_body:"null"); /* handle close from remote end: this will exit the client */ if (eof){ clixon_debug(CLIXON_DBG_STREAM, "eof"); @@ -230,7 +229,7 @@ restconf_stream_cb(int s, clixon_exit_set(1); goto done; } - if ((ret = clixon_xml_parse_string(cbuf_get(cbmsg), YB_NONE, NULL, &xt, NULL)) < 0) + if ((ret = clixon_xml_parse_string(cbuf_get(cbmsg), YB_NONE, NULL, &xtop, NULL)) < 0) goto done; if (ret == 0){ clixon_err(OE_XML, EFAULT, "Invalid notification"); @@ -266,8 +265,6 @@ restconf_stream_cb(int s, clixon_debug(CLIXON_DBG_STREAM, "retval: %d", retval); if (xtop != NULL) xml_free(xtop); - if (reply) - free(reply); if (cbmsg) cbuf_free(cbmsg); if (cb) diff --git a/lib/clixon/clixon_proto.h b/lib/clixon/clixon_proto.h index e7744b005..77802bd98 100644 --- a/lib/clixon/clixon_proto.h +++ b/lib/clixon/clixon_proto.h @@ -75,7 +75,7 @@ int clixon_msg_send10(int s, const char *descr, cbuf *cb); int clixon_rpc10(int sock, const char *descr, cbuf *msgin, cbuf *msgret, int *eof); /* NETCONF 1.1 */ -int clixon_msg_rcv11(int s, const char *descr, cbuf **cb, int *eof); +int clixon_msg_rcv11(int s, const char *descr, int intr, cbuf **cb, int *eof); int clicon_rpc(int sock, const char *descr, struct clicon_msg *msg, char **xret, int *eof); int send_msg_reply(int s, const char *descr, char *data, uint32_t datalen); int send_msg_notify_xml(clixon_handle h, int s, const char *descr, cxobj *xev); diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 3e785c4b2..d3da591ca 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -572,9 +572,17 @@ clixon_msg_send11(int s, return retval; } +static void +atomicio_sig_handler(int arg) +{ + _atomicio_sig++; +} + /*! Receive a message using unified NETCONF w chunked framing * * @param[in] s socket (unix or inet) to communicate with backend + * @param[in] descr Description of peer for logging + * @param[in] intr If set, make a ^C cause an error (OBSOLETE?) * @param[out] cb cligen buf struct containing the incoming message * @param[out] eof Set if eof encountered * @retval 0 OK (check eof) @@ -585,6 +593,7 @@ clixon_msg_send11(int s, int clixon_msg_rcv11(int s, const char *descr, + int intr, cbuf **cb, int *eof) { @@ -600,12 +609,22 @@ clixon_msg_rcv11(int s, int eom = 0; cxobj *xtop = NULL; cxobj *xerr = NULL; + sigset_t oldsigset; + struct sigaction oldsigaction[32] = {{{0,},},}; if ((cbmsg = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; } eom = 0; + *eof = 0; + if (intr){ + if (clixon_signal_save(&oldsigset, oldsigaction) < 0) + goto done; + set_signal(SIGINT, SIG_IGN, NULL); + clicon_signal_unblock(SIGINT); + set_signal_flags(SIGINT, 0, atomicio_sig_handler, NULL); + } while (*eof == 0 && eom == 0) { /* Read input data from socket and append to cbbuf */ if ((len = netconf_input_read2(s, buf, buflen, eof)) < 0) @@ -638,6 +657,10 @@ clixon_msg_rcv11(int s, retval = 0; done: clixon_debug(CLIXON_DBG_MSG|CLIXON_DBG_DETAIL, "%s done", __FUNCTION__); + if (intr){ + if (clixon_signal_restore(&oldsigset, oldsigaction) < 0) + goto done; + } if (cbmsg) cbuf_free(cbmsg); if (xtop) @@ -680,7 +703,7 @@ clicon_rpc(int sock, goto done; if (cbsend) cbuf_free(cbsend); - if (clixon_msg_rcv11(sock, descr, &cbrcv, eof) < 0) + if (clixon_msg_rcv11(sock, descr, 0, &cbrcv, eof) < 0) goto done; if (*eof) goto ok; @@ -693,7 +716,7 @@ clicon_rpc(int sock, } ok: retval = 0; - done: + done: clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "retval:%d", retval); if (reply) free(reply); diff --git a/test/test_snmp_set.sh b/test/test_snmp_set.sh index 97739d23c..a00c68b0c 100755 --- a/test/test_snmp_set.sh +++ b/test/test_snmp_set.sh @@ -133,7 +133,7 @@ function testinit(){ new "wait backend" wait_backend - + if [ $SN -ne 0 ]; then # Kill old clixon_snmp, if any new "Terminating any old clixon_snmp processes" @@ -269,8 +269,10 @@ if [ $BE -ne 0 ]; then fi sudo pkill -f clixon_backend - - new "Starting backend" +fi + +if [ $BE -ne 0 ]; then + new "Starting backend -s startup -f $cfg -- -V CLIXON-TYPES-MIB/clixonExampleScalars/clixonExampleInteger" start_backend -s startup -f $cfg -- -V CLIXON-TYPES-MIB/clixonExampleScalars/clixonExampleInteger fi