AC_DEFUN([PDNS_CHECK_CLOCK_GETTIME],[
OLD_LIBS="$LIBS"; LIBS=""
- AC_SEARCH_LIBS([clock_gettime], [rt])
+ AC_SEARCH_LIBS([clock_gettime], [rt], [AC_DEFINE(HAVE_CLOCK_GETTIME, [1], [Define to 1 if you have clock_gettime])])
AC_SUBST([RT_LIBS],[$LIBS])
LIBS="$OLD_LIBS"
])
dnswriter.cc \
ednsoptions.cc ednsoptions.hh \
ednssubnet.cc \
+ gettime.cc gettime.hh \
gss_context.cc gss_context.hh \
iputils.cc \
logger.cc \
#include "delaypipe.hh"
#include "misc.hh"
+#include "gettime.hh"
#include <thread>
template<class T>
template<class T>
void DelayPipe<T>::gettime(struct timespec* ts)
{
-#ifdef __MACH__ // this is a 'limp home' solution since it doesn't do monotonic time. see http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x
- struct timeval tv;
- gettimeofday(&tv, 0);
- ts->tv_sec = tv.tv_sec;
- ts->tv_nsec = tv.tv_usec * 1000;
-#else
- clock_gettime(CLOCK_MONOTONIC, ts);
-#endif
+ ::gettime(ts);
}
#include "sodcrypto.hh"
#include "base64.hh"
#include "lock.hh"
+#include "gettime.hh"
#include <map>
#include <fstream>
#include <boost/logic/tribool.hpp>
{
counts_t counts;
struct timespec cutoff, mintime, now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
cutoff = mintime = now;
cutoff.tv_sec -= seconds;
{
counts_t counts;
struct timespec cutoff, mintime, now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
cutoff = mintime = now;
cutoff.tv_sec -= seconds;
setLuaNoSideEffect();
auto slow = g_dynblockNMG.getCopy();
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
boost::format fmt("%-24s %8d %8d %s\n");
g_outputBuffer = (fmt % "Netmask" % "Seconds" % "Blocks" % "Reason").str();
for(const auto& e: slow) {
setLuaSideEffect();
auto slow = g_dynblockNMG.getCopy();
struct timespec until, now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
until=now;
int actualSeconds = seconds ? *seconds : 10;
until.tv_sec += actualSeconds;
unsigned int num=0;
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
std::multimap<struct timespec, string> out;
#include "config.h"
#include "dnsdist.hh"
+#include "gettime.hh"
#include "dnsparser.hh"
#include "dnsdist-protobuf.hh"
message.set_inbytes(dq.len);
struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
+ gettime(&ts, true);
message.set_timesec(ts.tv_sec);
message.set_timeusec(ts.tv_nsec / 1000);
message.set_id(ntohs(dq.dh->id));
#include "ednsoptions.hh"
#include "dolog.hh"
#include "lock.hh"
+#include "gettime.hh"
#include <thread>
#include <atomic>
string poolname;
int delayMsec=0;
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
if (!processQuery(localDynBlockNMG, localRulactions, blockFilter, dq, poolname, &delayMsec, now)) {
goto drop;
g_stats.responses++;
struct timespec answertime;
- clock_gettime(CLOCK_MONOTONIC, &answertime);
+ gettime(&answertime);
unsigned int udiff = 1000000.0*DiffTime(now,answertime);
{
std::lock_guard<std::mutex> lock(g_rings.respMutex);
#include "ext/incbin/incbin.h"
#include "htmlfiles.h"
#include "base64.hh"
+#include "gettime.hh"
static bool compareAuthorization(YaHTTP::Request& req, const string &expected_password, const string& expectedApiKey)
Json::object obj;
auto slow = g_dynblockNMG.getCopy();
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
for(const auto& e: slow) {
if(now < e->second.until ) {
Json::object thing{{"reason", e->second.reason}, {"seconds", (double)(e->second.until.tv_sec - now.tv_sec)},
#include "lock.hh"
#include <getopt.h>
#include "dnsdist-cache.hh"
+#include "gettime.hh"
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
{
struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ gettime(&ts);
std::lock_guard<std::mutex> lock(g_rings.respMutex);
g_rings.respRing.push_back({ts, ids->origRemote, ids->qname, ids->qtype, (unsigned int)udiff, (unsigned int)got, *dh, state->remote});
}
string poolname;
int delayMsec=0;
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime(&now);
if (!processQuery(localDynBlock, localRulactions, blockFilter, dq, poolname, &delayMsec, now))
{
dss->reuseds++;
--dss->outstanding;
struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ gettime(&ts);
struct dnsheader fake;
memset(&fake, 0, sizeof(fake));
#include "sholder.hh"
#include "dnscrypt.hh"
#include "dnsdist-cache.hh"
+#include "gettime.hh"
#ifdef HAVE_PROTOBUF
#include <boost/uuid/uuid.hpp>
struct StopWatch
{
-#ifndef CLOCK_MONOTONIC_RAW
-#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
-#endif
struct timespec d_start{0,0};
void start() {
- if(clock_gettime(CLOCK_MONOTONIC_RAW, &d_start) < 0)
+ if(gettime(&d_start) < 0)
unixDie("Getting timestamp");
}
double udiff() const {
struct timespec now;
- if(clock_gettime(CLOCK_MONOTONIC_RAW, &now) < 0)
+ if(gettime(&now) < 0)
unixDie("Getting timestamp");
return 1000000.0*(now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec)/1000.0;
double udiffAndSet() {
struct timespec now;
- if(clock_gettime(CLOCK_MONOTONIC_RAW, &now) < 0)
+ if(gettime(&now) < 0)
unixDie("Getting timestamp");
auto ret= 1000000.0*(now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec)/1000.0;
ednsoptions.cc ednsoptions.hh \
ednscookies.cc ednscookies.hh \
ednssubnet.cc ednssubnet.hh \
+ gettime.cc gettime.hh \
iputils.cc iputils.hh \
lock.hh \
misc.cc misc.hh \
ednsoptions.cc ednsoptions.hh \
ednscookies.cc ednscookies.hh \
ednssubnet.cc ednssubnet.hh \
+ gettime.cc gettime.hh \
iputils.cc iputils.hh \
misc.cc misc.hh \
namespaces.hh \
--- /dev/null
+../gettime.cc
\ No newline at end of file
--- /dev/null
+../gettime.hh
\ No newline at end of file
--- /dev/null
+#include "gettime.hh"
+#include "config.h"
+
+#ifdef HAVE_CLOCK_GETTIME
+#include <time.h>
+
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
+#endif
+
+int gettime(struct timespec *tp, bool needRealTime)
+{
+ return clock_gettime(needRealTime ? CLOCK_REALTIME : CLOCK_MONOTONIC_RAW, tp);
+}
+
+#else
+#include <sys/time.h>
+
+int gettime(struct timespec *tp, bool needRealTime)
+{
+ struct timeval tv;
+
+ int ret = gettimeofday(&tv, NULL);
+ if(ret < 0) return ret;
+
+ tp->tv_sec = tv.tv_sec;
+ tp->tv_nsec = tv.tv_usec * 1000;
+ return ret;
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+#pragma once
+
+extern int gettime(struct timespec *tp, bool needRealTime=false);
#include "validate-recursor.hh"
#include "rec-lua-conf.hh"
#include "ednsoptions.hh"
+#include "gettime.hh"
#ifdef HAVE_PROTOBUF
#include <boost/uuid/uuid.hpp>
}
struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
+ gettime(&ts, true);
message.set_timesec(ts.tv_sec);
message.set_timeusec(ts.tv_nsec / 1000);
message.set_id(ntohs(dc->d_mdp.d_header.id));
ednsoptions.cc ednsoptions.hh \
ednssubnet.cc ednssubnet.hh \
filterpo.cc filterpo.hh \
+ gettime.cc gettime.hh \
gss_context.cc gss_context.hh \
iputils.hh iputils.cc \
ixfr.cc ixfr.hh \
fi
])
+PDNS_CHECK_CLOCK_GETTIME
+
BOOST_REQUIRE([1.35])
PDNS_SELECT_CONTEXT_IMPL
--- /dev/null
+../gettime.cc
\ No newline at end of file
--- /dev/null
+../gettime.hh
\ No newline at end of file
--- /dev/null
+../../../m4/pdns_check_clock_gettime.m4
\ No newline at end of file