summaryrefslogtreecommitdiff
path: root/libc/inet/resolv.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-04-03 11:50:50 +0000
committerEric Andersen <andersen@codepoet.org>2002-04-03 11:50:50 +0000
commit7b8eeeceed5bf59b7e9558e1535f3012bb246375 (patch)
tree287372764fde9b45ba563dd15eefde4ded8d6772 /libc/inet/resolv.c
parent810ad656d66dacbb2c84c9fe80d22f60d96dbc4d (diff)
Patch from Jim Treadway <jim@stardot-tech.com> to eliminate
use of alarm() and therefore SIGARLM in the resolver and to instead use select, which is much cleaner.
Diffstat (limited to 'libc/inet/resolv.c')
-rw-r--r--libc/inet/resolv.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 29094541a..ae99ea068 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -530,12 +530,6 @@ int form_query(int id, const char *name, int type, unsigned char *packet,
#ifdef L_dnslookup
-int dns_caught_signal = 0;
-void dns_catch_signal(int signo)
-{
- dns_caught_signal = 1;
-}
-
int dns_lookup(const char *name, int type, int nscount, char **nsip,
unsigned char **outpacket, struct resolv_answer *a)
{
@@ -546,8 +540,8 @@ int dns_lookup(const char *name, int type, int nscount, char **nsip,
#ifdef __UCLIBC_HAS_IPV6__
struct sockaddr_in6 sa6;
#endif /* __UCLIBC_HAS_IPV6__ */
- int oldalarm;
- __sighandler_t oldhandler;
+ struct timeval tv;
+ fd_set fds;
struct resolv_header h;
struct resolv_question q;
int retries = 0;
@@ -652,23 +646,19 @@ int dns_lookup(const char *name, int type, int nscount, char **nsip,
send(fd, packet, len, 0);
- dns_caught_signal = 0;
- oldalarm = alarm(REPLY_TIMEOUT);
- oldhandler = signal(SIGALRM, dns_catch_signal);
-
- i = recv(fd, packet, PACKETSZ, 0);
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ tv.tv_sec = REPLY_TIMEOUT;
+ tv.tv_usec = 0;
+ if (select(fd + 1, &fds, NULL, NULL, &tv) <= 0) {
+ DPRINTF("Timeout\n");
- alarm(0);
- signal(SIGALRM, oldhandler);
- alarm(oldalarm);
-
- DPRINTF("Timeout=%d, len=%d\n", dns_caught_signal, i);
-
- if (dns_caught_signal)
- /* timed out, so retry send and receive,
- to next nameserver on queue */
+ /* timed out, so retry send and receive,
+ * to next nameserver on queue */
goto again;
+ }
+ i = recv(fd, packet, 512, 0);
if (i < HFIXEDSZ)
/* too short ! */
goto again;