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)
downloadopenssh-git-795b86313f1f1aab9691666c4f2d5dae6e4acd50.tar.gz
- (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 deb8768f..099c4ef8 100644
--- a/misc.c
+++ b/misc.c
@@ -882,17 +882,24 @@ ms_to_timeval(struct timeval *tv, int ms)
time_t
monotime(void)
{
-#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+#if defined(HAVE_CLOCK_GETTIME) && \
+ (defined(CLOCK_MONOTONIC) || defined(CLOCK_BOOTTIME))
struct timespec ts;
static int gettime_failed = 0;
if (!gettime_failed) {
+#if defined(CLOCK_BOOTTIME)
+ if (clock_gettime(CLOCK_BOOTTIME, &ts) == 0)
+ return (ts.tv_sec);
+#endif
+#if defined(CLOCK_MONOTONIC)
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
return (ts.tv_sec);
+#endif
debug3("clock_gettime: %s", strerror(errno));
gettime_failed = 1;
}
-#endif
+#endif /* HAVE_CLOCK_GETTIME && (CLOCK_MONOTONIC || CLOCK_BOOTTIME */
return time(NULL);
}