mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
To: musl@lists.openwall.com
Cc: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Subject: [musl] [PATCH] dns: Prefer monotonic clock for DNS lookup timeouts
Date: Thu, 29 Dec 2022 21:21:32 -0600	[thread overview]
Message-ID: <20221230032132.14003-1-AWilcox@Wilcox-Tech.com> (raw)
In-Reply-To: <0737A458-7E17-4C2C-B702-7A40FAA6151A@adelielinux.org>

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.
---
 src/network/res_msend.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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;
 }
-- 
2.37.1 (Apple Git-137.1)


      reply	other threads:[~2022-12-30  3:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 11:24 [musl] " Gregor Jasny
2022-12-01 15:11 ` Rich Felker
2022-12-30  3:20   ` A. Wilcox
2022-12-30  3:21     ` A. Wilcox [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221230032132.14003-1-AWilcox@Wilcox-Tech.com \
    --to=awilcox@wilcox-tech.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).