949ac9fd479e06e49d216cf1dd64394ebc7e96ff
[openwrt.git] / package / busybox / patches / 610-syslog-remote-retry-connection.patch
1 --- a/sysklogd/syslogd.c
2 +++ b/sysklogd/syslogd.c
3 @@ -98,6 +98,8 @@ struct globals {
4         GLOBALS
5  
6  #if ENABLE_FEATURE_REMOTE_LOG
7 +       len_and_sockaddr *remoteAddr;
8 +       int remoteFD;
9         llist_t *remoteHosts;
10  #endif
11  #if ENABLE_FEATURE_IPC_SYSLOG
12 @@ -554,6 +556,7 @@ static void do_syslogd(void) NORETURN;
13  static void do_syslogd(void)
14  {
15         int sock_fd;
16 +       int send_err = 0;
17  #if ENABLE_FEATURE_REMOTE_LOG
18         llist_t *item;
19  #endif
20 @@ -637,10 +640,23 @@ static void do_syslogd(void)
21                                         continue;
22                         }
23                         /* Send message to remote logger, ignore possible error */
24 -                       /* TODO: on some errors, close and set G.remoteFD to -1
25 -                        * so that DNS resolution and connect is retried? */
26 -                       sendto(rh->remoteFD, recvbuf, sz+1, MSG_DONTWAIT,
27 -                               &(rh->remoteAddr->u.sa), rh->remoteAddr->len);
28 +                       if (sendto(rh->remoteFD, recvbuf, sz+1, MSG_DONTWAIT,
29 +                               &G.remoteAddr->u.sa, G.remoteAddr->len)  == -1 ) {
30 +                               send_err = errno;
31 +                       }
32 +
33 +                       /* On some errors, close and set G.remoteFD to -1
34 +                        * so that DNS resolution and connect is retried */
35 +                       switch (send_err) {
36 +                               case ECONNRESET:
37 +                               case EDESTADDRREQ:
38 +                               case EISCONN:
39 +                               case ENOTCONN:
40 +                               case EPIPE:
41 +                                       close(G.remoteFD);
42 +                                       G.remoteFD = -1;
43 +                                       break;
44 +                       }
45                 }
46  #endif
47                 if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) {