Skip to content

Commit

Permalink
Internal framing: fcgi error
Browse files Browse the repository at this point in the history
CLI continue error
enable msg recv interrupt
  • Loading branch information
olofhagsand committed Feb 28, 2024
1 parent 520f8a9 commit 4138f39
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/backend/backend_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/cli_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion apps/netconf/netconf_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
9 changes: 3 additions & 6 deletions apps/restconf/restconf_stream_fcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/clixon/clixon_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 25 additions & 2 deletions lib/src/clixon_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -585,6 +593,7 @@ clixon_msg_send11(int s,
int
clixon_msg_rcv11(int s,
const char *descr,
int intr,
cbuf **cb,
int *eof)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions test/test_snmp_set.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 4138f39

Please sign in to comment.