From cbcdb1b162d40b932c16937251aea6fe6448842d Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 4 Jun 2019 14:21:33 +0200 Subject: [PATCH] Port calidns to openbsd and other systems without recvmmsg or sched_setscheduler. (cherry picked from commit 63fd0bc9d43bf51c5471aea8b25cd0b6f3aa4029) --- configure.ac | 4 +++- pdns/Makefile.am | 2 -- pdns/calidns.cc | 55 +++++++++++++++++++++++++++++++----------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/configure.ac b/configure.ac index 501661e6a..02d93318f 100644 --- a/configure.ac +++ b/configure.ac @@ -130,10 +130,12 @@ PDNS_CHECK_VIRTUALENV PDNS_FROM_GIT dnl Checks for library functions. -AC_CHECK_FUNCS_ONCE([strcasestr localtime_r recvmmsg getrandom arc4random]) +AC_CHECK_FUNCS_ONCE([strcasestr localtime_r recvmmsg sched_setscheduler getrandom arc4random]) AM_CONDITIONAL([HAVE_RECVMMSG], [test "x$ac_cv_func_recvmmsg" = "xyes"]) +AM_CONDITIONAL([HAVE_SCHED_SETSCHEDULER], [test "x$ac_cv_func_sched_setscheduler" = "xyes"]) + AS_IF([test "x$lt_cv_dlopen" = "xno"], [AC_MSG_ERROR([Your system does not support dlopen])] ) diff --git a/pdns/Makefile.am b/pdns/Makefile.am index edf380e96..b29a58686 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -99,9 +99,7 @@ bin_PROGRAMS += \ ixplore \ sdig -if HAVE_RECVMMSG bin_PROGRAMS += calidns -endif if HAVE_BOOST_GE_148 bin_PROGRAMS += \ diff --git a/pdns/calidns.cc b/pdns/calidns.cc index f2c8bb0a3..06862882a 100644 --- a/pdns/calidns.cc +++ b/pdns/calidns.cc @@ -68,37 +68,52 @@ static void* recvThread(const vector* sockets) int err; +#if HAVE_RECVMMSG vector buf(100); for(auto& m : buf) { fillMSGHdr(&m.msg_hdr, new struct iovec, new char[512], 512, new char[1500], 1500, new ComboAddress("127.0.0.1")); } +#else + struct msghdr buf; + fillMSGHdr(&buf, new struct iovec, new char[512], 512, new char[1500], 1500, new ComboAddress("127.0.0.1")); +#endif while(!g_done) { fds=rfds; err = poll(&fds[0], fds.size(), -1); - if(err < 0) { - if(errno==EINTR) - continue; + if (err < 0) { + if (errno == EINTR) + continue; unixDie("Unable to poll for new UDP events"); - } - + } + for(auto &pfd : fds) { - if(pfd.revents & POLLIN) { - - if((err=recvmmsg(pfd.fd, &buf[0], buf.size(), MSG_WAITFORONE, 0)) < 0 ) { - if(errno != EAGAIN) - cerr<<"recvfrom gave error, ignoring: "<* sockets, const vectorsize(), &dest); + fillMSGHdr(&u.msgh, &u.iov, nullptr, 0, (char*)&(*p)[0], p->size(), &dest); if((ret=sendmsg((*sockets)[count % sockets->size()]->getHandle(), &u.msgh, 0))) if(ret < 0) - unixDie("sendmmsg"); + unixDie("sendmsg"); if(!(count%burst)) { @@ -339,11 +354,13 @@ try struct sched_param param; param.sched_priority=99; +#if HAVE_SCHED_SETSCHEDULER if(sched_setscheduler(0, SCHED_FIFO, ¶m) < 0) { if (!g_quiet) { cerr<<"Unable to set SCHED_FIFO: "<()); string line; -- 2.40.0