summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2014-05-21 17:12:53 +1000
committerDamien Miller <djm@mindrot.org>2014-05-21 17:12:53 +1000
commit795b86313f1f1aab9691666c4f2d5dae6e4acd50 (patch)
tree213a840a32d78f5189b39b943502975620927fb1 /misc.c
parent18912775cb97c0b1e75e838d3c7d4b56648137b5 (diff)
- (djm) [misc.c] Use CLOCK_BOOTTIME in preference to CLOCK_MONOTONIC
when it is available. It takes into account time spent suspended, thereby ensuring timeouts (e.g. for expiring agent keys) fire correctly. bz#2228 reported by John Haxby
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/misc.c b/misc.c
index deb8768f3..099c4ef80 100644
--- a/misc.c
+++ b/misc.c
@@ -882,17 +882,24 @@ ms_to_timeval(struct timeval *tv, int ms)
882time_t 882time_t
883monotime(void) 883monotime(void)
884{ 884{
885#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) 885#if defined(HAVE_CLOCK_GETTIME) && \
886 (defined(CLOCK_MONOTONIC) || defined(CLOCK_BOOTTIME))
886 struct timespec ts; 887 struct timespec ts;
887 static int gettime_failed = 0; 888 static int gettime_failed = 0;
888 889
889 if (!gettime_failed) { 890 if (!gettime_failed) {
891#if defined(CLOCK_BOOTTIME)
892 if (clock_gettime(CLOCK_BOOTTIME, &ts) == 0)
893 return (ts.tv_sec);
894#endif
895#if defined(CLOCK_MONOTONIC)
890 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 896 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
891 return (ts.tv_sec); 897 return (ts.tv_sec);
898#endif
892 debug3("clock_gettime: %s", strerror(errno)); 899 debug3("clock_gettime: %s", strerror(errno));
893 gettime_failed = 1; 900 gettime_failed = 1;
894 } 901 }
895#endif 902#endif /* HAVE_CLOCK_GETTIME && (CLOCK_MONOTONIC || CLOCK_BOOTTIME */
896 903
897 return time(NULL); 904 return time(NULL);
898} 905}