shell: unify endofname() in hush and ash
[oweals/busybox.git] / sysklogd / syslogd.c
index 6bc450bf998bc0fe696ce928e4486eacf08fc957..fb7309538153a99eb9d7d4693da5b417e6c4573b 100644 (file)
@@ -10,7 +10,7 @@
  *
  * Maintainer: Gennady Feldman <gfeldman@gena01.com> as of Mar 12, 2001
  *
- * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /*
@@ -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)) {