From 94396b7f06f512a0acb230640d7f703fb802a9ee Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Thu, 8 Aug 2013 11:52:37 +1000 Subject: - (dtucker) [misc.c] Fall back to time(2) at runtime if clock_gettime( CLOCK_MONOTONIC...) fails. Some older versions of RHEL have the CLOCK_MONOTONIC define but don't actually support it. Found and tested by Kevin Brott, ok djm. --- ChangeLog | 4 ++++ misc.c | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ca13ebe..2813200a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ - (dtucker) [regress/Makefile regress/test-exec.sh] Don't try to use test -nt since some platforms (eg really old FreeBSD) don't have it. Instead, run "make clean" before a complete regress run. ok djm. + - (dtucker) [misc.c] Fall back to time(2) at runtime if clock_gettime( + CLOCK_MONOTONIC...) fails. Some older versions of RHEL have the + CLOCK_MONOTONIC define but don't actually support it. Found and tested + by Kevin Brott, ok djm. 20130804 - (dtucker) [auth-krb5.c configure.ac openbsd-compat/bsd-misc.h] Add support diff --git a/misc.c b/misc.c index 2bdfb650..85c40421 100644 --- a/misc.c +++ b/misc.c @@ -854,19 +854,24 @@ ms_to_timeval(struct timeval *tv, int ms) tv->tv_usec = (ms % 1000) * 1000; } +#define clock_gettime(a,b) -1 + time_t monotime(void) { #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) struct timespec ts; + static int gettime_failed = 0; - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - fatal("clock_gettime: %s", strerror(errno)); + if (!gettime_failed) { + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) + return (ts.tv_sec); + debug3("clock_gettime: %s", strerror(errno)); + gettime_failed = 1; + } +#endif - return (ts.tv_sec); -#else return time(NULL); -#endif } void -- cgit v1.2.3