summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2022-12-29 21:21:32 -0600
committerRich Felker <dalias@aerifal.cx>2023-02-12 18:03:24 -0500
commit7d756e1c04de6eb3f2b3d3e1141a218bb329fcfb (patch)
treebeaef48969dcb8c8fe74cef00a910e78402611cb /src
parent07616721f1fa6cb215ffbef23441cae80412484f (diff)
downloadmusl-7d756e1c04de6eb3f2b3d3e1141a218bb329fcfb.tar.gz
musl-7d756e1c04de6eb3f2b3d3e1141a218bb329fcfb.tar.bz2
musl-7d756e1c04de6eb3f2b3d3e1141a218bb329fcfb.tar.xz
musl-7d756e1c04de6eb3f2b3d3e1141a218bb329fcfb.zip
dns: prefer monotonic clock for timeouts
Before this commit, DNS timeouts always used CLOCK_REALTIME, which could produce spurious timeouts or delays if wall time changed for whatever reason. Now we try CLOCK_MONOTONIC and only fall back to CLOCK_REALTIME when it is unavailable.
Diffstat (limited to 'src')
-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;
}