--- ./sysklogd/syslogd.c.udplog 2006-03-07 21:55:28.000000000 +0100 +++ ./sysklogd/syslogd.c 2006-03-07 21:56:27.000000000 +0100 @@ -414,6 +414,10 @@ memset(&listen_udp_addr, 0, sizeof(listen_udp_addr)); listen_udp_fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fcntl(listen_udp_fd, F_SETFL, O_NONBLOCK) < 0) { + bb_perror_msg_and_die("Couldn't make UDP socket non-blocking"); + } + if (listen_udp_fd < 0) { bb_error_msg("cannot create socket"); } @@ -468,19 +472,16 @@ /* if we have a valid socket, send the message */ if (-1 != remotefd) { - now = 1; + now = 5; /* used as a retry counter */ snprintf(line, sizeof(line), "<%d>%s", pri, msg); - retry: /* send message to remote logger */ - if(( -1 == sendto(remotefd, line, strlen(line), 0, - (struct sockaddr *) &remoteaddr, - sizeof(remoteaddr))) && (errno == EINTR)) { - /* sleep now seconds and retry (with now * 2) */ - sleep(now); - now *= 2; - goto retry; - } + while ((now-- > 0) && + ( -1 == sendto(remotefd, line, strlen(line), + MSG_NOSIGNAL, + (struct sockaddr *) &remoteaddr, + sizeof(remoteaddr))) && + (errno == EINTR)); } } @@ -591,6 +592,10 @@ _PATH_LOG); } + if (fcntl(sock_fd, F_SETFL, O_NONBLOCK) < 0) { + bb_perror_msg_and_die("Couldn't mark UNIX socket " _PATH_LOG " non-blocking"); + } + addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) { bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG); @@ -658,7 +663,7 @@ if ((i = recv(sock_fd, tmpbuf, TMP_BUF_SZ, 0)) > 0) { tmpbuf[i] = '\0'; serveConnection(tmpbuf, i); - } else { + } else if (i < 0 && errno != EINTR && errno != EAGAIN) { bb_perror_msg_and_die("UNIX socket error"); } } /* FD_ISSET() */ @@ -670,6 +675,8 @@ if ((i = recv(listen_udp_fd, tmpbuf, TMP_BUF_SZ, 0)) > 0) { tmpbuf[i] = '\0'; serveConnection(tmpbuf, i); + } else if (i < 0 && errno != EINTR && errno != EAGAIN) { + bb_perror_msg_and_die("UDP socket error"); } } /* FD_ISSET() */ #endif /* SYSLOG_LISTEN_UDP */ @@ -769,6 +776,7 @@ if(daemon(0, 1) < 0) bb_perror_msg_and_die("daemon"); #endif /* __uClinux__ */ + close(0); close(1); close(2); } doSyslogd();