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;
+ }
}
}
}
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);