From: Ian Jackson Date: Mon, 30 Mar 2020 17:12:00 +0000 (+0100) Subject: Use CLOCK_MONOTONIC for all our timing needs, when possible X-Git-Tag: v0.6.1~2 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=commitdiff_plain;h=cb2f54fd3ec011600ddda023b8f2d8ec5250bb8f;hp=21e16fbf18b62a36be886d7c15d1671d3971db66 Use CLOCK_MONOTONIC for all our timing needs, when possible Otherwise we can malfunction if the clock warps. This depends on an unreleased adns feature, so the warning is currently not actually printed. Signed-off-by: Ian Jackson --- diff --git a/configure b/configure index 7cf4421..d076bd3 100755 --- a/configure +++ b/configure @@ -4250,9 +4250,7 @@ $as_echo "#define USE_MONOTONIC 1" >>confdefs.h else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Using non-monotonic clock, due to lack of adns_if_monotonic" >&5 -$as_echo "$as_me: WARNING: Using non-monotonic clock, due to lack of adns_if_monotonic" >&2;} - +: fi diff --git a/configure.ac b/configure.ac index 53810e4..aceed90 100644 --- a/configure.ac +++ b/configure.ac @@ -140,7 +140,7 @@ fi AC_CHECK_DECL([adns_if_monotonic],[ AC_DEFINE([USE_MONOTONIC],[1],[Use CLOCK_MONOTONIC and adns_if_monotonic]) ],[ - AC_MSG_WARN([Using non-monotonic clock, due to lack of adns_if_monotonic]) +: dnl AC_MSG_WARN([Using non-monotonic clock, due to lack of adns_if_monotonic]) ],[AC_INCLUDES_DEFAULT #include ]) diff --git a/resolver.c b/resolver.c index 45738ea..3f9a6d5 100644 --- a/resolver.c +++ b/resolver.c @@ -211,6 +211,9 @@ static list_t *adnsresolver_apply(closure_t *self, struct cloc loc, conf=dict_read_string(d,"config",False,"adns",loc); adns_initflags iflags = 0; +#if USE_MONOTONIC + iflags |= adns_if_monotonic; +#endif if (conf) { if (adns_init_strcfg(&st->ast, iflags, 0, conf)) { diff --git a/secnet.c b/secnet.c index e15ee81..177c2ef 100644 --- a/secnet.c +++ b/secnet.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -356,9 +357,18 @@ static void run(void) int allocdfds=0, shortfall=0; do { +#if USE_MONOTONIC + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts)!=0) { + fatal_perror("main loop: clock_gettime(CLOCK_MONOTONIC,)"); + } + tv_now_global.tv_sec = ts.tv_sec; + tv_now_global.tv_usec = ts.tv_nsec / 1000; +#else /* !USE_MONOTONIC */ if (gettimeofday(&tv_now_global, NULL)!=0) { fatal_perror("main loop: gettimeofday"); } +#endif /* !USE_MONOTONIC */ now_global=((uint64_t)tv_now_global.tv_sec*(uint64_t)1000)+ ((uint64_t)tv_now_global.tv_usec/(uint64_t)1000); idx=0;