mirror of
https://github.com/sheumann/hush.git
synced 2024-08-21 11:28:57 +00:00
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:
parent
87f3b26b3a
commit
d7ecd863c8
@ -471,8 +471,7 @@ static void do_syslogd(void) ATTRIBUTE_NORETURN;
|
||||
static void do_syslogd(void)
|
||||
{
|
||||
struct sockaddr_un sunx;
|
||||
struct pollfd pfd[1];
|
||||
#define sock_fd (pfd[0].fd)
|
||||
int sock_fd;
|
||||
char *dev_log_name;
|
||||
|
||||
/* Set up signal handlers */
|
||||
@ -526,40 +525,34 @@ static void do_syslogd(void)
|
||||
(char*)"syslogd started: BusyBox v" BB_VER, 0);
|
||||
|
||||
for (;;) {
|
||||
/*pfd[0].fd = sock_fd;*/
|
||||
pfd[0].events = POLLIN;
|
||||
pfd[0].revents = 0;
|
||||
if (poll(pfd, 1, -1) < 0) { /* -1: no timeout */
|
||||
if (errno == EINTR) {
|
||||
/* alarm may have happened */
|
||||
size_t sz;
|
||||
|
||||
sz = read(sock_fd, G.recvbuf, MAX_READ - 1);
|
||||
if (sz <= 0) {
|
||||
if (sz == 0)
|
||||
continue; /* EOF from unix socket??? */
|
||||
if (errno == EINTR) /* alarm may have happened */
|
||||
continue;
|
||||
}
|
||||
bb_perror_msg_and_die("poll");
|
||||
bb_perror_msg_and_die("read from /dev/log");
|
||||
}
|
||||
|
||||
if (pfd[0].revents) {
|
||||
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? */
|
||||
/* TODO: maybe suppress duplicates? */
|
||||
#if ENABLE_FEATURE_REMOTE_LOG
|
||||
/* We are not modifying log messages in any way before send */
|
||||
/* Remote site cannot trust _us_ anyway and need to do validation again */
|
||||
if (G.remoteAddr) {
|
||||
if (-1 == G.remoteFD) {
|
||||
G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0);
|
||||
}
|
||||
if (-1 != G.remoteFD) {
|
||||
/* send message to remote logger, ignore possible error */
|
||||
sendto(G.remoteFD, G.recvbuf, i, MSG_DONTWAIT,
|
||||
&G.remoteAddr->sa, G.remoteAddr->len);
|
||||
}
|
||||
/* We are not modifying log messages in any way before send */
|
||||
/* Remote site cannot trust _us_ anyway and need to do validation again */
|
||||
if (G.remoteAddr) {
|
||||
if (-1 == G.remoteFD) {
|
||||
G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0);
|
||||
}
|
||||
if (-1 != G.remoteFD) {
|
||||
/* send message to remote logger, ignore possible error */
|
||||
sendto(G.remoteFD, G.recvbuf, sz, MSG_DONTWAIT,
|
||||
&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 */
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user