From 9d52df5d44693f0a11e74c38218d6f85c56b957d Mon Sep 17 00:00:00 2001 From: des Date: Mon, 9 Oct 2006 09:58:58 +0000 Subject: [PATCH] Fix build on MacOS X: add a fake clock_gettime() and fix some includes. WARNING: varnish will build and run, but the lack of a monotonic clock may lead to strange behaviour if the clock is stepped (rather than skewed) while varnish is running. Thanks to Niklas Saers for providing a test environment. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1145 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_acceptor.c | 4 ++ .../bin/varnishd/cache_acceptor_epoll.c | 4 ++ .../bin/varnishd/cache_acceptor_kqueue.c | 4 ++ .../bin/varnishd/cache_acceptor_poll.c | 4 ++ varnish-cache/bin/varnishd/cache_ban.c | 2 + varnish-cache/bin/varnishd/cache_center.c | 4 ++ varnish-cache/bin/varnishd/cache_pass.c | 4 ++ varnish-cache/bin/varnishd/cache_pipe.c | 4 ++ varnish-cache/bin/varnishd/cache_response.c | 4 ++ varnish-cache/bin/varnishd/cache_vrt.c | 1 + varnish-cache/bin/varnishd/cache_vrt_acl.c | 2 + varnish-cache/bin/varnishd/cache_vrt_re.c | 2 + varnish-cache/bin/varnishd/hash_simple_list.c | 2 + varnish-cache/bin/varnishd/mgt_event.c | 4 ++ varnish-cache/bin/varnishd/rfc2616.c | 2 + varnish-cache/bin/varnishd/storage_malloc.c | 2 + varnish-cache/bin/varnishstat/varnishstat.c | 4 ++ varnish-cache/configure.ac | 1 + varnish-cache/include/Makefile.am | 1 + varnish-cache/include/compat/clock_gettime.h | 44 ++++++++++++++ varnish-cache/lib/libcompat/Makefile.am | 1 + varnish-cache/lib/libcompat/clock_gettime.c | 60 +++++++++++++++++++ 22 files changed, 160 insertions(+) create mode 100644 varnish-cache/include/compat/clock_gettime.h create mode 100644 varnish-cache/lib/libcompat/clock_gettime.c diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 73d5ab5c..ddddaaac 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -43,6 +43,10 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #ifndef HAVE_SRANDOMDEV #include "compat/srandomdev.h" #endif diff --git a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c index 6a29422d..be5796c1 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c @@ -41,6 +41,10 @@ #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "heritage.h" #include "shmlog.h" #include "cache.h" diff --git a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c index 41545da8..a82eec99 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c @@ -43,6 +43,10 @@ #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "heritage.h" #include "shmlog.h" #include "cache.h" diff --git a/varnish-cache/bin/varnishd/cache_acceptor_poll.c b/varnish-cache/bin/varnishd/cache_acceptor_poll.c index c6b3e505..6e16d5a5 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_poll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_poll.c @@ -42,6 +42,10 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "heritage.h" #include "shmlog.h" #include "cache.h" diff --git a/varnish-cache/bin/varnishd/cache_ban.c b/varnish-cache/bin/varnishd/cache_ban.c index dea28288..d5a77990 100644 --- a/varnish-cache/bin/varnishd/cache_ban.c +++ b/varnish-cache/bin/varnishd/cache_ban.c @@ -31,6 +31,8 @@ * Ban processing */ +#include + #include #include #include diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index fa3c12ca..0714599f 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -60,6 +60,10 @@ DOT start -> RECV #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "shmlog.h" #include "vcl.h" #include "cache.h" diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index 7df39b47..3861c98a 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -41,6 +41,10 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "shmlog.h" #include "cache.h" diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 5bf99156..359ddaa0 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -38,6 +38,10 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "shmlog.h" #include "heritage.h" #include "cache.h" diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 0ba7db10..b882485e 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -34,6 +34,10 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "shmlog.h" #include "heritage.h" #include "cache.h" diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 93638486..0dffc9b2 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -31,6 +31,7 @@ * Runtime support for compiled VCL programs */ +#include #include #include diff --git a/varnish-cache/bin/varnishd/cache_vrt_acl.c b/varnish-cache/bin/varnishd/cache_vrt_acl.c index 9ce33085..ad26b1dd 100644 --- a/varnish-cache/bin/varnishd/cache_vrt_acl.c +++ b/varnish-cache/bin/varnishd/cache_vrt_acl.c @@ -34,6 +34,8 @@ * XXX: a refresh facility. */ +#include + #include #include #include diff --git a/varnish-cache/bin/varnishd/cache_vrt_re.c b/varnish-cache/bin/varnishd/cache_vrt_re.c index 5318bb0d..36ce083e 100644 --- a/varnish-cache/bin/varnishd/cache_vrt_re.c +++ b/varnish-cache/bin/varnishd/cache_vrt_re.c @@ -31,6 +31,8 @@ * Runtime support for compiled VCL programs, regexps */ +#include + #include #include #include diff --git a/varnish-cache/bin/varnishd/hash_simple_list.c b/varnish-cache/bin/varnishd/hash_simple_list.c index a5785a70..9d294fa0 100644 --- a/varnish-cache/bin/varnishd/hash_simple_list.c +++ b/varnish-cache/bin/varnishd/hash_simple_list.c @@ -31,6 +31,8 @@ * This is the reference hash(/lookup) implementation */ +#include + #include #include #include diff --git a/varnish-cache/bin/varnishd/mgt_event.c b/varnish-cache/bin/varnishd/mgt_event.c index b98bdaad..112b11d6 100644 --- a/varnish-cache/bin/varnishd/mgt_event.c +++ b/varnish-cache/bin/varnishd/mgt_event.c @@ -37,6 +37,10 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "mgt.h" #include "mgt_event.h" #include "miniobj.h" diff --git a/varnish-cache/bin/varnishd/rfc2616.c b/varnish-cache/bin/varnishd/rfc2616.c index fdfc3d5f..be56c743 100644 --- a/varnish-cache/bin/varnishd/rfc2616.c +++ b/varnish-cache/bin/varnishd/rfc2616.c @@ -29,6 +29,8 @@ * $Id$ */ +#include + #include #include #include diff --git a/varnish-cache/bin/varnishd/storage_malloc.c b/varnish-cache/bin/varnishd/storage_malloc.c index 2a24fc25..0ddd20ae 100644 --- a/varnish-cache/bin/varnishd/storage_malloc.c +++ b/varnish-cache/bin/varnishd/storage_malloc.c @@ -31,6 +31,8 @@ * Storage method based on malloc(3) */ +#include + #include #include "cache.h" diff --git a/varnish-cache/bin/varnishstat/varnishstat.c b/varnish-cache/bin/varnishstat/varnishstat.c index 93374d34..b2305b92 100644 --- a/varnish-cache/bin/varnishstat/varnishstat.c +++ b/varnish-cache/bin/varnishstat/varnishstat.c @@ -39,6 +39,10 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" diff --git a/varnish-cache/configure.ac b/varnish-cache/configure.ac index a9ffae52..95182bec 100644 --- a/varnish-cache/configure.ac +++ b/varnish-cache/configure.ac @@ -78,6 +78,7 @@ AC_CHECK_FUNCS([srandomdev]) AC_CHECK_FUNCS([strlcat strlcpy]) AC_CHECK_FUNCS([strndup]) AC_CHECK_FUNCS([vis strvis strvisx]) +AC_CHECK_FUNCS([clock_gettime]) # Check which mechanism to use for the acceptor AC_CHECK_FUNCS([kqueue]) diff --git a/varnish-cache/include/Makefile.am b/varnish-cache/include/Makefile.am index e9a5e28b..af9f1aa9 100644 --- a/varnish-cache/include/Makefile.am +++ b/varnish-cache/include/Makefile.am @@ -6,6 +6,7 @@ noinst_HEADERS = \ cli_common.h \ cli_priv.h \ compat/asprintf.h \ + compat/clock_gettime.h \ compat/setproctitle.h \ compat/srandomdev.h \ compat/strlcat.h \ diff --git a/varnish-cache/include/compat/clock_gettime.h b/varnish-cache/include/compat/clock_gettime.h new file mode 100644 index 00000000..03367dd8 --- /dev/null +++ b/varnish-cache/include/compat/clock_gettime.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * All rights reserved. + * + * Author: Dag-Erling Smørgrav + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +#ifndef COMPAT_CLOCK_GETTIME_H_INCLUDED +#define COMPAT_CLOCK_GETTIME_H_INCLUDED + +#ifndef HAVE_CLOCK_GETTIME +typedef enum { + CLOCK_REALTIME, + CLOCK_MONOTONIC, +} clockid_t; + +int clock_gettime(clockid_t clk_id, struct timespec *tp); +#endif + +#endif diff --git a/varnish-cache/lib/libcompat/Makefile.am b/varnish-cache/lib/libcompat/Makefile.am index 885d3a07..7bbeada8 100644 --- a/varnish-cache/lib/libcompat/Makefile.am +++ b/varnish-cache/lib/libcompat/Makefile.am @@ -6,6 +6,7 @@ noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = \ asprintf.c \ + clock_gettime.c \ vasprintf.c \ setproctitle.c \ srandomdev.c \ diff --git a/varnish-cache/lib/libcompat/clock_gettime.c b/varnish-cache/lib/libcompat/clock_gettime.c new file mode 100644 index 00000000..7bca9e6f --- /dev/null +++ b/varnish-cache/lib/libcompat/clock_gettime.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * All rights reserved. + * + * Author: Dag-Erling Smørgrav + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + * + */ + +#ifndef HAVE_CLOCK_GETTIME + +#include + +#include +#include + +#include "compat/clock_gettime.h" + +int +clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + struct timeval tv; + + switch (clk_id) { + case CLOCK_REALTIME: + case CLOCK_MONOTONIC: + if (gettimeofday(&tv, NULL) != 0) + return (-1); + tp->tv_sec = tv.tv_sec; + tp->tv_nsec = tv.tv_usec * 1000; + return (0); + default: + errno = EINVAL; + return (-1); + } +} +#endif -- 2.39.5