summaryrefslogtreecommitdiff
path: root/libexec/identd/identd.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-01-17 19:48:09 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-01-17 19:48:09 +0000
commite3b072f345a56b3da0afe3c84a3ef4e584850bd0 (patch)
treed4909e60875f594296173181a166296729986cb4 /libexec/identd/identd.c
parent2c62f5d3afca7509e025edcb54184a020eb14283 (diff)
avoid fd_set overflow by using poll(); avoid syslog() in signal handler by using flag checked in main loop
Diffstat (limited to 'libexec/identd/identd.c')
-rw-r--r--libexec/identd/identd.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/libexec/identd/identd.c b/libexec/identd/identd.c
index 40271172290..20cc5104d28 100644
--- a/libexec/identd/identd.c
+++ b/libexec/identd/identd.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <poll.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
@@ -108,15 +109,15 @@ gethost6(addr)
return(hbuf[bb]);
}
+sig_atomic_t alarm_fired;
+
/*
* Exit cleanly after our time's up.
*/
static void
alarm_handler()
{
- if (syslog_flag)
- syslog(LOG_DEBUG, "SIGALRM triggered, exiting");
- exit(0);
+ alarm_fired = 1;
}
/*
@@ -134,7 +135,6 @@ main(argc, argv)
struct sockaddr_in6 * sin6;
struct in_addr laddr, faddr;
struct in6_addr laddr6, faddr6;
- struct timeval tv;
struct passwd *pwd;
struct group *grp;
int background_flag = 0;
@@ -313,7 +313,7 @@ main(argc, argv)
*/
if (background_flag) {
int nfds, fd;
- fd_set read_set;
+ struct pollfd pfd[1];
/*
* Loop and dispatch client handling processes
@@ -326,20 +326,23 @@ main(argc, argv)
signal(SIGALRM, alarm_handler);
alarm(timeout);
}
+
/*
* Wait for a connection request to occur.
* Ignore EINTR (Interrupted System Call).
*/
do {
- FD_ZERO(&read_set);
- FD_SET(0, &read_set);
-
- if (timeout) {
- tv.tv_sec = timeout;
- tv.tv_usec = 0;
- nfds = select(1, &read_set, NULL, NULL, &tv);
- } else
- nfds = select(1, &read_set, NULL, NULL, NULL);
+ if (alarm_fired) {
+ if (syslog_flag)
+ syslog(LOG_DEBUG,
+ "SIGALRM triggered, exiting");
+ exit(0);
+ }
+
+ pfd[0].fd = 0;
+ pfd[0].events = POLLIN;
+
+ nfds = poll(pfd, 1, timeout * 1000);
} while (nfds < 0 && errno == EINTR);
/*