diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-07 13:53:32 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-07 13:53:32 +0000 |
commit | d7ecd863c855a53e263486e742a4adfb871d9127 (patch) | |
tree | d9ea1332db4276aca54a6c18510c863ab4b59776 /sysklogd | |
parent | 87f3b26b3a17369c12f4f9a70d6845796f8648d6 (diff) | |
download | busybox-w32-d7ecd863c855a53e263486e742a4adfb871d9127.tar.gz busybox-w32-d7ecd863c855a53e263486e742a4adfb871d9127.tar.bz2 busybox-w32-d7ecd863c855a53e263486e742a4adfb871d9127.zip |
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
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/syslogd.c | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index ae3f1a2eb..f27bd8379 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -471,8 +471,7 @@ static void do_syslogd(void) ATTRIBUTE_NORETURN; | |||
471 | static void do_syslogd(void) | 471 | static void do_syslogd(void) |
472 | { | 472 | { |
473 | struct sockaddr_un sunx; | 473 | struct sockaddr_un sunx; |
474 | struct pollfd pfd[1]; | 474 | int sock_fd; |
475 | #define sock_fd (pfd[0].fd) | ||
476 | char *dev_log_name; | 475 | char *dev_log_name; |
477 | 476 | ||
478 | /* Set up signal handlers */ | 477 | /* Set up signal handlers */ |
@@ -526,40 +525,34 @@ static void do_syslogd(void) | |||
526 | (char*)"syslogd started: BusyBox v" BB_VER, 0); | 525 | (char*)"syslogd started: BusyBox v" BB_VER, 0); |
527 | 526 | ||
528 | for (;;) { | 527 | for (;;) { |
529 | /*pfd[0].fd = sock_fd;*/ | 528 | size_t sz; |
530 | pfd[0].events = POLLIN; | 529 | |
531 | pfd[0].revents = 0; | 530 | sz = read(sock_fd, G.recvbuf, MAX_READ - 1); |
532 | if (poll(pfd, 1, -1) < 0) { /* -1: no timeout */ | 531 | if (sz <= 0) { |
533 | if (errno == EINTR) { | 532 | if (sz == 0) |
534 | /* alarm may have happened */ | 533 | continue; /* EOF from unix socket??? */ |
534 | if (errno == EINTR) /* alarm may have happened */ | ||
535 | continue; | 535 | continue; |
536 | } | 536 | bb_perror_msg_and_die("read from /dev/log"); |
537 | bb_perror_msg_and_die("poll"); | ||
538 | } | 537 | } |
539 | 538 | ||
540 | if (pfd[0].revents) { | 539 | /* TODO: maybe suppress duplicates? */ |
541 | int i; | ||
542 | i = read(sock_fd, G.recvbuf, MAX_READ - 1); | ||
543 | if (i <= 0) | ||
544 | bb_perror_msg_and_die("UNIX socket error"); | ||
545 | /* TODO: maybe suppress duplicates? */ | ||
546 | #if ENABLE_FEATURE_REMOTE_LOG | 540 | #if ENABLE_FEATURE_REMOTE_LOG |
547 | /* We are not modifying log messages in any way before send */ | 541 | /* We are not modifying log messages in any way before send */ |
548 | /* Remote site cannot trust _us_ anyway and need to do validation again */ | 542 | /* Remote site cannot trust _us_ anyway and need to do validation again */ |
549 | if (G.remoteAddr) { | 543 | if (G.remoteAddr) { |
550 | if (-1 == G.remoteFD) { | 544 | if (-1 == G.remoteFD) { |
551 | G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); | 545 | G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); |
552 | } | 546 | } |
553 | if (-1 != G.remoteFD) { | 547 | if (-1 != G.remoteFD) { |
554 | /* send message to remote logger, ignore possible error */ | 548 | /* send message to remote logger, ignore possible error */ |
555 | sendto(G.remoteFD, G.recvbuf, i, MSG_DONTWAIT, | 549 | sendto(G.remoteFD, G.recvbuf, sz, MSG_DONTWAIT, |
556 | &G.remoteAddr->sa, G.remoteAddr->len); | 550 | &G.remoteAddr->sa, G.remoteAddr->len); |
557 | } | ||
558 | } | 551 | } |
559 | #endif | ||
560 | G.recvbuf[i] = '\0'; | ||
561 | split_escape_and_log(G.recvbuf, i); | ||
562 | } | 552 | } |
553 | #endif | ||
554 | G.recvbuf[sz] = '\0'; | ||
555 | split_escape_and_log(G.recvbuf, sz); | ||
563 | } /* for */ | 556 | } /* for */ |
564 | } | 557 | } |
565 | 558 | ||