From c512a7cfb0adaf6c75b61a9427e94d0b88c26946 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 31 Dec 2015 12:10:59 +0100 Subject: syslogd: prepare select() for dealing with timeouts and signals We don't want to immediately continue on signal as we'll want better handling of sigalarm as well as being able to handle timeouts. --- sysklogd/syslogd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 9374838..1ee712c 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -687,6 +687,8 @@ static void doSyslogd(void) for (;;) { int nbfd; + int ret; + FD_ZERO(&fds); if (doListenUnix) { FD_SET(sock_fd, &fds); @@ -708,14 +710,16 @@ static void doSyslogd(void) nbfd = klog_fd + 1; } #endif - if (select(nbfd, &fds, NULL, NULL, NULL) < 0) { - if (errno == EINTR) { - /* alarm may have happened. */ - continue; - } + + ret = select(nbfd, &fds, NULL, NULL, NULL); + if (ret < 0 && errno != EINTR) { bb_perror_msg_and_die("select error"); } + /* alarm, timeout, etc */ + if (ret <= 0) + continue; + #if MAXLINE > BUFSIZ # define TMP_BUF_SZ BUFSIZ #else -- 1.7.12.1