summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2013-08-08 11:52:37 +1000
committerDarren Tucker <dtucker@zip.com.au>2013-08-08 11:52:37 +1000
commit94396b7f06f512a0acb230640d7f703fb802a9ee (patch)
tree1b4dd673bcbfe9acd5d08e4e1ae44e06ff86e379 /misc.c
parenta5a3cbfa0fb8ef011d3e7b38910a13f6ebbb8818 (diff)
- (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.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/misc.c b/misc.c
index 2bdfb6507..85c404218 100644
--- a/misc.c
+++ b/misc.c
@@ -854,19 +854,24 @@ ms_to_timeval(struct timeval *tv, int ms)
854 tv->tv_usec = (ms % 1000) * 1000; 854 tv->tv_usec = (ms % 1000) * 1000;
855} 855}
856 856
857#define clock_gettime(a,b) -1
858
857time_t 859time_t
858monotime(void) 860monotime(void)
859{ 861{
860#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) 862#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
861 struct timespec ts; 863 struct timespec ts;
864 static int gettime_failed = 0;
862 865
863 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) 866 if (!gettime_failed) {
864 fatal("clock_gettime: %s", strerror(errno)); 867 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
868 return (ts.tv_sec);
869 debug3("clock_gettime: %s", strerror(errno));
870 gettime_failed = 1;
871 }
872#endif
865 873
866 return (ts.tv_sec);
867#else
868 return time(NULL); 874 return time(NULL);
869#endif
870} 875}
871 876
872void 877void