From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14277 invoked from network); 30 Dec 2022 03:22:37 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 30 Dec 2022 03:22:37 -0000 Received: (qmail 3435 invoked by uid 550); 30 Dec 2022 03:22:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3396 invoked from network); 30 Dec 2022 03:22:34 -0000 From: "A. Wilcox" To: musl@lists.openwall.com Cc: "A. Wilcox" Date: Thu, 29 Dec 2022 21:21:32 -0600 Message-Id: <20221230032132.14003-1-AWilcox@Wilcox-Tech.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <0737A458-7E17-4C2C-B702-7A40FAA6151A@adelielinux.org> References: <0737A458-7E17-4C2C-B702-7A40FAA6151A@adelielinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] dns: Prefer monotonic clock for DNS lookup timeouts 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)