From 24578767e7f8d2eeb10bf78e99fb32426b193cee Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Sun, 7 May 2017 16:14:49 +0200 Subject: [PATCH] sigpipe problems --- apps/backend/backend_client.c | 16 ++++++++++++++-- apps/backend/clixon_backend_handle.c | 4 ++-- lib/src/clixon_proto.c | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index f5e26f8d..ce424606 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -871,9 +871,21 @@ from_client_msg(clicon_handle h, assert(cbuf_len(cbret)); clicon_debug(1, "%s %s", __FUNCTION__, cbuf_get(cbret)); if (send_msg_reply(ce->ce_s, cbuf_get(cbret), cbuf_len(cbret)+1) < 0){ - if (errno == ECONNRESET) + switch (errno){ + case EPIPE: + /* man (2) write: + * EPIPE fd is connected to a pipe or socket whose reading end is + * closed. When this happens the writing process will also receive + * a SIGPIPE signal. + * In Clixon this means a client, eg restconf, netconf or cli closes + * the (UNIX domain) socket. + */ + case ECONNRESET: clicon_log(LOG_WARNING, "client rpc reset"); - goto done; + break; + default: + goto done; + } } // ok: retval = 0; diff --git a/apps/backend/clixon_backend_handle.c b/apps/backend/clixon_backend_handle.c index be2cb07c..14808d1d 100644 --- a/apps/backend/clixon_backend_handle.c +++ b/apps/backend/clixon_backend_handle.c @@ -147,7 +147,7 @@ backend_notify(clicon_handle h, if (strcmp(su->su_stream, stream) == 0){ if (strlen(su->su_filter)==0 || fnmatch(su->su_filter, event, 0) == 0){ if (send_msg_notify(ce->ce_s, level, event) < 0){ - if (errno == ECONNRESET){ + if (errno == ECONNRESET || errno == EPIPE){ clicon_log(LOG_WARNING, "client %d reset", ce->ce_nr); #if 0 /* We should remove here but removal is not possible @@ -225,7 +225,7 @@ backend_notify_xml(clicon_handle h, goto done; } if (send_msg_notify(ce->ce_s, level, cbuf_get(cb)) < 0){ - if (errno == ECONNRESET){ + if (errno == ECONNRESET || errno == EPIPE){ clicon_log(LOG_WARNING, "client %d reset", ce->ce_nr); #if 0 /* We should remove here but removal is not possible diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 172aa696..990e1766 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -297,8 +297,11 @@ clicon_msg_send(int s, if (atomicio((ssize_t (*)(int, void *, size_t))write, s, msg, ntohs(msg->op_len)) < 0){ clicon_err(OE_CFG, errno, "%s", __FUNCTION__); + clicon_log(LOG_WARNING, "%s: write: %s len:%d msg:%s", __FUNCTION__, + strerror(errno), ntohs(msg->op_len), msg->op_body); goto done; } + ok: retval = 0; done: return retval;