summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2022-12-29 21:15:50 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2022-12-29 21:15:50 -0600
commit009c2456c15567fcc1baa581ec203e4677956e5c (patch)
tree5b1718d4557eff526b446f566d3af6cc6090c1dd
parent8f9259450aa43a6fd539e428e61e2961b725fbae (diff)
downloadmusl-awilfox/monotonic-dns.tar.gz
musl-awilfox/monotonic-dns.tar.bz2
musl-awilfox/monotonic-dns.tar.xz
musl-awilfox/monotonic-dns.zip
dns: Prefer monotonic clock for DNS lookup timeoutsawilfox/monotonic-dns
Before this commit, DNS timeouts always used CLOCK_REALTIME, which could produce errors if wall time changed for whatever reason. Now we try CLOCK_MONOTONIC and only fall back to CLOCK_REALTIME when it is unavailable.
-rw-r--r--src/network/res_msend.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/network/res_msend.c b/src/network/res_msend.c
index 11c6aa0e..fef7e3a2 100644
--- a/src/network/res_msend.c
+++ b/src/network/res_msend.c
@@ -25,7 +25,8 @@ static void cleanup(void *p)
static unsigned long mtime()
{
struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0 && errno == ENOSYS)
+ clock_gettime(CLOCK_REALTIME, &ts);
return (unsigned long)ts.tv_sec * 1000
+ ts.tv_nsec / 1000000;
}