From: Sam Tannous Date: Tue, 8 Jul 2014 19:15:44 +0000 (-0400) Subject: make agentx socket non-blocking X-Git-Tag: 0.7.10~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b93e39a167360898368640eb2a113ce7b5cea9f4;p=thirdparty%2Flldpd.git make agentx socket non-blocking This patch makes the lldpd socket non-blocking. And also adds a brief retry. Signed-off-by: Roopa Prabhu Signed-off-by: Sam Tannous --- diff --git a/src/daemon/agent_priv.c b/src/daemon/agent_priv.c index 10929e47..88e8e958 100644 --- a/src/daemon/agent_priv.c +++ b/src/daemon/agent_priv.c @@ -80,12 +80,27 @@ static int agent_priv_unix_send(netsnmp_transport *t, void *buf, int size, void **opaque, int *olength) { - int rc = -1; + int rc = -1, retry = 4; + useconds_t usecs = 250000; + if (t != NULL && t->sock >= 0) { while (rc < 0) { rc = send(t->sock, buf, size, 0); - if (rc < 0 && errno != EINTR) { - break; + if (rc < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + if (--retry <= 0) + break; + + log_info("snmp", "%s: retrying after " + "%d secs...\n", __FUNCTION__, + usecs); + usleep(usecs); + continue; + } else if (errno != EINTR) { + log_info("snmp", "%s: failed with %s\n", + __FUNCTION__, strerror(errno)); + break; + } } } } diff --git a/src/daemon/priv.c b/src/daemon/priv.c index b6341e44..187d90d9 100644 --- a/src/daemon/priv.c +++ b/src/daemon/priv.c @@ -354,6 +354,17 @@ asroot_snmp_socket() must_write(PRIV_PRIVILEGED, &rc, sizeof(int)); return; } + + if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { + log_warn("privsep", "cannot set sock %s to non-block : %s", + addr->sun_path, strerror(errno)); + + close(sock); + rc = -1; + must_write(PRIV_PRIVILEGED, &rc, sizeof(int)); + return; + } + must_write(PRIV_PRIVILEGED, &rc, sizeof(int)); send_fd(PRIV_PRIVILEGED, sock); close(sock);