summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dickinson <cshore@csolve.net>2010-08-03 02:26:20 (GMT)
committer Denys Vlasenko <vda.linux@googlemail.com>2010-08-03 02:26:20 (GMT)
commite74d79866c6d125527e3ba69245a087a28fd19ce (patch)
tree5daf6b4b5f95290a4342bc02b2b1780182c69566
parent6e06da5efd5d6e341ae2f5116c449994740f5613 (diff)
downloadbusybox-e74d79866c6d125527e3ba69245a087a28fd19ce.tar.gz
busybox-e74d79866c6d125527e3ba69245a087a28fd19ce.tar.bz2
syslogd: close/re-resolve/reopen remote sockets on some sendto() errors
function old new delta syslogd_main 1201 1262 +61 Signed-off-by: Daniel Dickinson <cshore@csolve.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--sysklogd/syslogd.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 6bc450b..37a119b 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -546,7 +546,7 @@ static int try_to_resolve_remote(remoteHost_t *rh)
if (!rh->remoteAddr)
return -1;
}
- return socket(rh->remoteAddr->u.sa.sa_family, SOCK_DGRAM, 0);
+ return xsocket(rh->remoteAddr->u.sa.sa_family, SOCK_DGRAM, 0);
}
#endif
@@ -636,11 +636,25 @@ static void do_syslogd(void)
if (rh->remoteFD == -1)
continue;
}
- /* Send message to remote logger, ignore possible error */
- /* TODO: on some errors, close and set G.remoteFD to -1
- * so that DNS resolution and connect is retried? */
- sendto(rh->remoteFD, recvbuf, sz+1, MSG_DONTWAIT,
- &(rh->remoteAddr->u.sa), rh->remoteAddr->len);
+
+ /* Send message to remote logger.
+ * On some errors, close and set remoteFD to -1
+ * so that DNS resolution is retried.
+ */
+ if (sendto(rh->remoteFD, recvbuf, sz+1,
+ MSG_DONTWAIT | MSG_NOSIGNAL,
+ &(rh->remoteAddr->u.sa), rh->remoteAddr->len) == -1
+ ) {
+ switch (errno) {
+ case ECONNRESET:
+ case ENOTCONN: /* paranoia */
+ case EPIPE:
+ close(rh->remoteFD);
+ rh->remoteFD = -1;
+ free(rh->remoteAddr);
+ rh->remoteAddr = NULL;
+ }
+ }
}
#endif
if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) {