From e6361ebda4ec964091d6147c1d36ca749ed05ebd Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 1 Sep 2015 22:16:11 +0200 Subject: [PATCH] collectd-tg: Fall back to gettimeofday(3) if clock_gettime(3) is not available. Sometimes Mac OS/X is stupid. clock_gettime() was introduced in 1997, just sayin'. Fixes: #1247 --- src/collectd-tg.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/collectd-tg.c b/src/collectd-tg.c index 80473e0e..05cf9a76 100644 --- a/src/collectd-tg.c +++ b/src/collectd-tg.c @@ -100,6 +100,7 @@ static void signal_handler (int signal) /* {{{ */ loop = 0; } /* }}} void signal_handler */ +#if HAVE_CLOCK_GETTIME static double dtime (void) /* {{{ */ { struct timespec ts = { 0 }; @@ -109,6 +110,18 @@ static double dtime (void) /* {{{ */ return ((double) ts.tv_sec) + (((double) ts.tv_nsec) / 1e9); } /* }}} double dtime */ +#else +/* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */ +static double dtime (void) /* {{{ */ +{ + struct timeval tv = { 0 }; + + if (gettimeofday (&tv, /* timezone = */ NULL) != 0) + perror ("gettimeofday"); + + return ((double) tv.tv_sec) + (((double) tv.tv_usec) / 1e6); +} /* }}} double dtime */ +#endif static int compare_time (const void *v0, const void *v1) /* {{{ */ { -- 2.30.2