Hi, This piece of code now uses poll() instead of select(). I have not got round to test this yet, but I will as soon as I have a working setup.
Thoughts? =================================================================== RCS file: /cvs/src/usr.sbin/amd/amd/info_hes.c,v retrieving revision 1.13 diff -u -p -r1.13 info_hes.c --- info_hes.c 24 Feb 2012 06:19:00 -0000 1.13 +++ info_hes.c 7 May 2014 13:38:21 -0000 @@ -66,7 +66,7 @@ #endif static int soacnt; -static struct timeval hs_timeout; +static int hs_timeout; static int servernum; #endif /* HAS_HESIOD_RELOAD */ @@ -261,12 +261,11 @@ hs_res_send(char *buf, int buflen, char */ for (retry = _res.retry; retry > 0; retry--) { for (ns = 0; ns < hs_nscount; ns++) { - hs_timeout.tv_sec = - (_res.retrans << (_res.retry - retry)) - / hs_nscount; - if (hs_timeout.tv_sec <= 0) - hs_timeout.tv_sec = 1; - hs_timeout.tv_usec = 0; + hs_timeout = _res.retrans << (_res.retry - retry); + hs_timeout /= hs_nscount; + hs_timeout *= 1000; + if (hs_timeout <= 0) + hs_timeout = 1000; if (s < 0) { s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { @@ -340,7 +339,7 @@ hs_readresp(int s, char *answer, int ans cp = answer; len = sizeof(short); while (len != 0 && - (n = hs_res_vcread(s, (char *)cp, (int)len, &hs_timeout)) > 0) { + (n = hs_res_vcread(s, (char *)cp, (int)len, hs_timeout)) > 0) { cp += n; len -= n; } @@ -354,7 +353,7 @@ hs_readresp(int s, char *answer, int ans return(-1); } while (len != 0 && - (n = hs_res_vcread(s, (char *)cp, (int)len, &hs_timeout)) > 0) { + (n = hs_res_vcread(s, (char *)cp, (int)len, hs_timeout)) > 0) { cp += n; len -= n; } @@ -364,7 +363,7 @@ hs_readresp(int s, char *answer, int ans } int -hs_res_vcread(int sock, char *buf, int buflen, struct timeval *timeout) +hs_res_vcread(int sock, char *buf, int buflen, int timeout) { int n; @@ -375,24 +374,16 @@ hs_res_vcread(int sock, char *buf, int b } int -hs_res_selwait(int sock, struct timeval timeout) +hs_res_selwait(int sock, int timeout) { - fd_set *fdsp; - int fdsn; - int n; + struct pollfd pfd[1]; /* * Wait for reply */ - fdsn = howmany(sock+1, NFDBITS) * sizeof(fd_mask); - if ((fdsp = (fd_set *)malloc(fdsn)) == NULL) - return(0); - memset(fdsp, 0, fdsn); - - FD_SET(sock, fdsp); - n = select(sock+1, fdsp, NULL, NULL, timeout); - free(fdsp); - return(n); + pfd[0].fd = sock; + pfd[0].events = POLLIN; + return poll(pfd, 1, timeout); } /* Returns: