From: Remi Gacogne Date: Fri, 12 May 2023 15:42:27 +0000 (+0200) Subject: dnsdist: Hopefully make clang-tidy happy X-Git-Tag: rec-5.0.0-alpha1~161^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=35b27ac8d18b43702a63e4078b68776c66f561ab;p=thirdparty%2Fpdns.git dnsdist: Hopefully make clang-tidy happy --- diff --git a/pdns/channel.cc b/pdns/channel.cc index ae62d23693..262772b7f9 100644 --- a/pdns/channel.cc +++ b/pdns/channel.cc @@ -22,9 +22,7 @@ #include "channel.hh" -namespace pdns -{ -namespace channel +namespace pdns::channel { Notifier::Notifier(FDWrapper&& fd) : @@ -47,9 +45,7 @@ namespace channel if (errno == EAGAIN || errno == EWOULDBLOCK) { return false; } - else { - throw std::runtime_error("Unable to write to channel notifier pipe: " + stringerror()); - } + throw std::runtime_error("Unable to write to channel notifier pipe: " + stringerror()); } return true; } @@ -62,9 +58,9 @@ namespace channel void Waiter::clear() { - ssize_t got; + ssize_t got{0}; do { - char data; + char data{0}; got = read(d_fd.getHandle(), &data, sizeof(data)); if (got == 0) { d_closed = true; @@ -73,7 +69,7 @@ namespace channel } throw std::runtime_error("EOF while clearing channel notifier pipe"); } - else if (got == -1) { + if (got == -1) { if (errno == EINTR) { continue; } @@ -82,7 +78,7 @@ namespace channel } throw std::runtime_error("Error while clearing channel notifier pipe: " + stringerror()); } - } while (got); + } while (got > 0); } int Waiter::getDescriptor() const @@ -92,8 +88,8 @@ namespace channel std::pair createNotificationQueue(bool nonBlocking, size_t pipeBufferSize, bool throwOnEOF) { - int fds[2] = {-1, -1}; - if (pipe(fds) < 0) { + std::array fds = {-1, -1}; + if (pipe(fds.data()) < 0) { throw std::runtime_error("Error creating notification channel pipe: " + stringerror()); } @@ -117,4 +113,3 @@ namespace channel return std::pair(Notifier(std::move(sender)), Waiter(std::move(receiver), throwOnEOF)); } } -} diff --git a/pdns/dnsdistdist/dnsdist-nghttp2.cc b/pdns/dnsdistdist/dnsdist-nghttp2.cc index 52403b9b04..9c505cdceb 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2.cc @@ -133,7 +133,11 @@ uint32_t DoHConnectionToBackend::getConcurrentStreamsCount() const void DoHConnectionToBackend::handleResponse(PendingRequest&& request) { - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); try { if (!d_healthCheckQuery) { @@ -175,7 +179,11 @@ void DoHConnectionToBackend::handleIOError() d_connectionDied = true; nghttp2_session_terminate_session(d_session.get(), NGHTTP2_PROTOCOL_ERROR); - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); for (auto& request : d_currentStreams) { handleResponseError(std::move(request.second), now); @@ -406,7 +414,11 @@ void DoHConnectionToBackend::handleReadableIOCallback(int fd, FDMultiplexer::fun throw std::runtime_error("Fatal error while passing received data to nghttp2: " + std::string(nghttp2_strerror((int)readlen))); } - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); conn->d_lastDataReceivedTime = now; @@ -496,7 +508,11 @@ void DoHConnectionToBackend::stopIO() void DoHConnectionToBackend::updateIO(IOState newState, FDMultiplexer::callbackfunc_t callback, bool noTTD) { - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); boost::optional ttd{boost::none}; if (!noTTD) { @@ -535,7 +551,11 @@ void DoHConnectionToBackend::watchForRemoteHostClosingConnection() void DoHConnectionToBackend::addToIOState(IOState state, FDMultiplexer::callbackfunc_t callback) { - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); boost::optional ttd{boost::none}; if (state == IOState::NeedRead) { @@ -649,7 +669,11 @@ int DoHConnectionToBackend::on_frame_recv_callback(nghttp2_session* session, con } else { vinfolog("HTTP response has a non-200 status code: %d", request.d_responseCode); - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); conn->handleResponseError(std::move(request), now); @@ -701,7 +725,11 @@ int DoHConnectionToBackend::on_data_chunk_recv_callback(nghttp2_session* session } else { vinfolog("HTTP response has a non-200 status code: %d", request.d_responseCode); - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); conn->handleResponseError(std::move(request), now); @@ -733,7 +761,11 @@ int DoHConnectionToBackend::on_stream_close_callback(nghttp2_session* session, i return 0; } - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); auto request = std::move(stream->second); conn->d_currentStreams.erase(stream->first); @@ -872,7 +904,10 @@ static void handleCrossProtocolQuery(int pipefd, FDMultiplexer::funcparam_t& par throw std::runtime_error("Error while reading from the DoH cross-protocol channel:" + std::string(e.what())); } - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; gettimeofday(&now, nullptr); std::shared_ptr tqs = cpq->getTCPQuerySender(); @@ -897,7 +932,11 @@ static void dohClientThread(pdns::channel::Receiver&& receiv DoHClientThreadData data(std::move(receiver)); data.mplexer->addReadFD(data.d_receiver.getDescriptor(), handleCrossProtocolQuery, &data); - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; + gettimeofday(&now, nullptr); time_t lastTimeoutScan = now.tv_sec; @@ -1088,7 +1127,10 @@ bool setupDoHClientProtocolNegotiation(std::shared_ptr& ctx) bool sendH2Query(const std::shared_ptr& ds, std::unique_ptr& mplexer, std::shared_ptr& sender, InternalQuery&& query, bool healthCheck) { #ifdef HAVE_NGHTTP2 - struct timeval now; + struct timeval now + { + .tv_sec = 0, .tv_usec = 0 + }; gettimeofday(&now, nullptr); if (healthCheck) { diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 57da686ee5..4573addbab 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -1272,7 +1272,7 @@ static void on_dnsdist(h2o_socket_t *listener, const char *err) for the CPU, the first thing we need to do is to send responses to free slots anyway, otherwise queries and responses are piling up in our pipes, consuming memory and likely coming up too late after the client has gone away */ - DOHServerConfig* dsc = reinterpret_cast(listener->data); + auto* dsc = static_cast(listener->data); while (true) { std::unique_ptr du{nullptr, DOHUnit::release}; try { @@ -1389,7 +1389,7 @@ static void on_accept(h2o_socket_t *listener, const char *err) static int create_listener(std::shared_ptr& dsc, int fd) { - auto sock = h2o_evloop_socket_create(dsc->h2o_ctx.loop, fd, H2O_SOCKET_FLAG_DONT_READ); + auto* sock = h2o_evloop_socket_create(dsc->h2o_ctx.loop, fd, H2O_SOCKET_FLAG_DONT_READ); sock->data = dsc.get(); h2o_socket_read_start(sock, on_accept); @@ -1617,7 +1617,7 @@ void dohThread(ClientState* cs) dsc->h2o_ctx.storage.entries[0].data = dsc.get(); ++dsc->h2o_ctx.storage.size; - auto sock = h2o_evloop_socket_create(dsc->h2o_ctx.loop, dsc->d_responseReceiver.getDescriptor(), H2O_SOCKET_FLAG_DONT_READ); + auto* sock = h2o_evloop_socket_create(dsc->h2o_ctx.loop, dsc->d_responseReceiver.getDescriptor(), H2O_SOCKET_FLAG_DONT_READ); sock->data = dsc.get(); // this listens to responses from dnsdist to turn into http responses