From ca786da156ebc556c75daa91dc010c353f974d11 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 6 Aug 2024 11:22:19 +0200 Subject: [PATCH] Fixed signal handling of recv message Revert to signal handling in 6.5 that was changed in the netconf uniform handling in 7.0 --- CHANGELOG.md | 2 ++ lib/src/clixon_netconf_input.c | 27 +++++++++++++++++++++------ lib/src/clixon_proto.c | 10 +++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdbd2af7..f149f1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ Developers may need to change their code ### Corrected Busg +* Fixed: Signal handling of recv message + Revert to signal handling in 6.5 that was changed in the netconf uniform handling in 7.0 * Fixed: [NETCONF error reply from failed leafref rquire-instance does not comply to RFC 7950](https://github.com/clicon/clixon/issues/536) ## 7.1.0 diff --git a/lib/src/clixon_netconf_input.c b/lib/src/clixon_netconf_input.c index 86af6241..46152f22 100644 --- a/lib/src/clixon_netconf_input.c +++ b/lib/src/clixon_netconf_input.c @@ -128,17 +128,32 @@ netconf_input_read2(int s, ssize_t buflen, int *eof) { - int retval = -1; - ssize_t len; + int retval = -1; + ssize_t len; + int restarts = 0; + int maxrestarts = 5; memset(buf, 0, buflen); - if ((len = read(s, buf, buflen)) < 0){ - if (errno == ECONNRESET) - len = 0; /* emulate EOF */ - else{ + while ((len = read(s, buf, buflen)) < 0) { + switch (errno){ + case EINTR: + case EAGAIN: + if (restarts++ >= maxrestarts){ + clixon_log(NULL, LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno)); + goto done; + } + break; /* Try again */ + case ECONNRESET: /* Connection reset by peer */ + case EPIPE: /* Client shutdown */ + case EBADF: /* Client shutdown - freebsd */ + len = 0; /* Emulate EOF */ + break; + default: clixon_log(NULL, LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno)); goto done; } + if (len == 0) + break; } /* read */ clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "len:%ld", len); if (len == 0){ /* EOF */ diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 5330690e..c9e0324e 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -549,7 +549,7 @@ clixon_msg_rcv11(int s, size_t frame_size = 0; unsigned char *p = buf; size_t plen; - cbuf *cbmsg=NULL; + cbuf *cbmsg = NULL; ssize_t len; int eom = 0; cxobj *xtop = NULL; @@ -557,10 +557,6 @@ clixon_msg_rcv11(int s, sigset_t oldsigset = {0,}; struct sigaction oldsigaction[32] = {{{0,},},}; - if ((cbmsg = cbuf_new()) == NULL){ - clixon_err(OE_XML, errno, "cbuf_new"); - goto done; - } eom = 0; *eof = 0; if (intr){ @@ -573,6 +569,10 @@ clixon_msg_rcv11(int s, /* May be more signals to ignore */ set_signal(SIGWINCH, SIG_IGN, NULL); } + if ((cbmsg = cbuf_new()) == NULL){ + clixon_err(OE_XML, errno, "cbuf_new"); + goto done; + } while (*eof == 0 && eom == 0) { /* Read input data from socket and append to cbbuf */ if ((len = netconf_input_read2(s, buf, buflen, eof)) < 0)