syslogd: do not need to poll(), we can just block in read().

function                                             old     new   delta
syslogd_main                                        1206    1106    -100
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-100)           Total: -100 bytes
   text    data     bss     dec     hex filename
 769820    1051   10764  781635   bed43 busybox_old
 769702    1051   10764  781517   beccd busybox_unstripped
This commit is contained in:
Denis Vlasenko 2007-09-07 13:53:32 +00:00
parent 87f3b26b3a
commit d7ecd863c8

View File

@ -471,8 +471,7 @@ static void do_syslogd(void) ATTRIBUTE_NORETURN;
static void do_syslogd(void) static void do_syslogd(void)
{ {
struct sockaddr_un sunx; struct sockaddr_un sunx;
struct pollfd pfd[1]; int sock_fd;
#define sock_fd (pfd[0].fd)
char *dev_log_name; char *dev_log_name;
/* Set up signal handlers */ /* Set up signal handlers */
@ -526,40 +525,34 @@ static void do_syslogd(void)
(char*)"syslogd started: BusyBox v" BB_VER, 0); (char*)"syslogd started: BusyBox v" BB_VER, 0);
for (;;) { for (;;) {
/*pfd[0].fd = sock_fd;*/ size_t sz;
pfd[0].events = POLLIN;
pfd[0].revents = 0; sz = read(sock_fd, G.recvbuf, MAX_READ - 1);
if (poll(pfd, 1, -1) < 0) { /* -1: no timeout */ if (sz <= 0) {
if (errno == EINTR) { if (sz == 0)
/* alarm may have happened */ continue; /* EOF from unix socket??? */
if (errno == EINTR) /* alarm may have happened */
continue; continue;
} bb_perror_msg_and_die("read from /dev/log");
bb_perror_msg_and_die("poll");
} }
if (pfd[0].revents) { /* TODO: maybe suppress duplicates? */
int i;
i = read(sock_fd, G.recvbuf, MAX_READ - 1);
if (i <= 0)
bb_perror_msg_and_die("UNIX socket error");
/* TODO: maybe suppress duplicates? */
#if ENABLE_FEATURE_REMOTE_LOG #if ENABLE_FEATURE_REMOTE_LOG
/* We are not modifying log messages in any way before send */ /* We are not modifying log messages in any way before send */
/* Remote site cannot trust _us_ anyway and need to do validation again */ /* Remote site cannot trust _us_ anyway and need to do validation again */
if (G.remoteAddr) { if (G.remoteAddr) {
if (-1 == G.remoteFD) { if (-1 == G.remoteFD) {
G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0);
} }
if (-1 != G.remoteFD) { if (-1 != G.remoteFD) {
/* send message to remote logger, ignore possible error */ /* send message to remote logger, ignore possible error */
sendto(G.remoteFD, G.recvbuf, i, MSG_DONTWAIT, sendto(G.remoteFD, G.recvbuf, sz, MSG_DONTWAIT,
&G.remoteAddr->sa, G.remoteAddr->len); &G.remoteAddr->sa, G.remoteAddr->len);
}
} }
#endif
G.recvbuf[i] = '\0';
split_escape_and_log(G.recvbuf, i);
} }
#endif
G.recvbuf[sz] = '\0';
split_escape_and_log(G.recvbuf, sz);
} /* for */ } /* for */
} }