]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
make agentx socket non-blocking
authorSam Tannous <stannous@cumulusnetworks.com>
Tue, 8 Jul 2014 19:15:44 +0000 (15:15 -0400)
committerVincent Bernat <vincent@bernat.im>
Tue, 8 Jul 2014 19:52:25 +0000 (21:52 +0200)
This patch makes the lldpd socket non-blocking. And also adds a brief
retry.

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: Sam Tannous <stannous@cumulusnetworks.com>
src/daemon/agent_priv.c
src/daemon/priv.c

index 10929e47223c4ff66541404eadb1fb8d8209c90b..88e8e95813c58392671a7c60d88e125b7ba4c1df 100644 (file)
@@ -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;
+                               }
                        }
                }
        }
index b6341e442daf8daafd976e4b895dc39cd5930e02..187d90d970f14f3d996a50263eb0c9e7cb52656d 100644 (file)
@@ -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);