]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Hopefully make clang-tidy happy
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 12 May 2023 15:42:27 +0000 (17:42 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 13 Jun 2023 07:59:45 +0000 (09:59 +0200)
pdns/channel.cc
pdns/dnsdistdist/dnsdist-nghttp2.cc
pdns/dnsdistdist/doh.cc

index ae62d23693b1b6ea0887054dfc79b1a496013421..262772b7f9e9e675ee206629af32e33dfc748438 100644 (file)
@@ -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<Notifier, Waiter> createNotificationQueue(bool nonBlocking, size_t pipeBufferSize, bool throwOnEOF)
   {
-    int fds[2] = {-1, -1};
-    if (pipe(fds) < 0) {
+    std::array<int, 2> 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));
   }
 }
-}
index 52403b9b048f74753741708079ae15d1d7544420..9c505cdcebe3cc295be23dd03098ebce54f8e137 100644 (file)
@@ -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<struct timeval> 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<struct timeval> 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<TCPQuerySender> tqs = cpq->getTCPQuerySender();
@@ -897,7 +932,11 @@ static void dohClientThread(pdns::channel::Receiver<CrossProtocolQuery>&& 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<TLSCtx>& ctx)
 bool sendH2Query(const std::shared_ptr<DownstreamState>& ds, std::unique_ptr<FDMultiplexer>& mplexer, std::shared_ptr<TCPQuerySender>& 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) {
index 57da686ee53f6481a4cc41c98e99262a2ba9cbdb..4573addbab885ac806a90ca1346430304c891a0e 100644 (file)
@@ -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<DOHServerConfig*>(listener->data);
+  auto* dsc = static_cast<DOHServerConfig*>(listener->data);
   while (true) {
     std::unique_ptr<DOHUnit, void(*)(DOHUnit*)> 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<DOHServerConfig>& 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