From 1fb260d101c1352ac880a0db945bfad984b1ef19 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Wed, 21 Oct 2015 11:29:05 +0330 Subject: [PATCH] - now depend on libpidutil [1] instead of FreeBSD specific libutil - cleanup Makefile and respect PREFIX - now builds on OS X on which clock_gettime() is not implemented --- Makefile | 6 +++--- ifstatd.c | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 862f713..6e5b675 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -PREFIX=/usr/local +PREFIX?=/usr/local INC=-I$(PREFIX)/include -LIB=-L$(PREFIX)/lib -lutil -FLAGS=-Wall -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 +LIB=-L$(PREFIX)/lib -lpidutil +FLAGS=-Wall -Wextra -O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing -mssse3 CC?=cc all: ifstatd_ diff --git a/ifstatd.c b/ifstatd.c index 1ccaef9..24d6bd0 100644 --- a/ifstatd.c +++ b/ifstatd.c @@ -46,7 +46,13 @@ #include #include #include -#include +#include +#include + +#ifdef __MACH__ +#include +#define CLOCK_REALTIME 0 +#endif #define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) #define RESOLUTION 10 @@ -70,6 +76,23 @@ char *pid_filename; char *cache_filename; struct pidfh *pfh; +#ifdef __MACH__ +/* clock_gettime is not implemented on OSX */ +int +clock_gettime(int clk_id, struct timespec *t) +{ + struct timeval now; + int rv = gettimeofday(&now, NULL); + + if (rv) + return rv; + t->tv_sec = now.tv_sec; + t->tv_nsec = now.tv_usec * 1000; + return 0; +} + +#endif + /* * Prepare for a clean shutdown */