summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorjlemon <jlemon@FreeBSD.org>2001-06-23 06:54:28 +0000
committerjlemon <jlemon@FreeBSD.org>2001-06-23 06:54:28 +0000
commit364df2ca4c5a5f54cb008109cefc506187073c29 (patch)
tree932d1cd580d2ef8f21858f9e0136b2780c6e92a7 /lib/libc
parent55113b084f1cb9716b488375027732e186a2c464 (diff)
downloadFreeBSD-src-364df2ca4c5a5f54cb008109cefc506187073c29.zip
FreeBSD-src-364df2ca4c5a5f54cb008109cefc506187073c29.tar.gz
Bring in fix from rev 1.32 that got lost during the conversion to kqueue.
This prevents an indefinte timeout in case the kevent call is interrupted for some reason. PR: 26665 MFC in: 2 weeks
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/net/res_send.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c
index 3513a49..e56b91f 100644
--- a/lib/libc/net/res_send.c
+++ b/lib/libc/net/res_send.c
@@ -598,7 +598,8 @@ read_len:
* Use datagrams.
*/
struct kevent kv;
- struct timespec timeout;
+ struct timespec ts;
+ struct timeval timeout, ctv;
struct sockaddr_storage from;
int fromlen;
@@ -707,7 +708,10 @@ read_len:
timeout.tv_sec /= _res.nscount;
if ((long) timeout.tv_sec <= 0)
timeout.tv_sec = 1;
- timeout.tv_nsec = 0;
+ timeout.tv_usec = 0;
+ TIMEVAL_TO_TIMESPEC(&timeout, &ts);
+ (void) gettimeofday(&ctv, NULL);
+ timeradd(&timeout, &ctv, &timeout);
wait:
if (s < 0) {
Perror(stderr, "s out-of-bounds", EMFILE);
@@ -717,13 +721,20 @@ read_len:
EV_SET(&kv, s, EVFILT_READ, EV_ADD | EV_ONESHOT, 0,0,0);
- n = _kevent(kq, &kv, 1, &kv, 1, &timeout);
+ n = _kevent(kq, &kv, 1, &kv, 1, &ts);
if (n < 0) {
- if (errno == EINTR)
- goto wait;
- Perror(stderr, "kevent", errno);
- res_close();
- goto next_ns;
+ if (errno == EINTR) {
+ (void) gettimeofday(&ctv, NULL);
+ if (timercmp(&ctv, &timeout, <)) {
+ timersub(&timeout, &ctv, &ctv);
+ TIMEVAL_TO_TIMESPEC(&ctv, &ts);
+ goto wait;
+ }
+ } else {
+ Perror(stderr, "kevent", errno);
+ res_close();
+ goto next_ns;
+ }
}
if (n == 0) {
OpenPOWER on IntegriCloud