]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Another batch
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 26 Jun 2019 14:55:19 +0000 (16:55 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 26 Jun 2019 14:55:19 +0000 (16:55 +0200)
22 files changed:
pdns/bpf-filter.cc
pdns/calidns.cc
pdns/comfun.cc
pdns/common_startup.cc
pdns/communicator.cc
pdns/devpollmplexer.cc
pdns/dns_random.cc
pdns/dnsdist-tcp.cc
pdns/dnsdist.cc
pdns/dnspacket.cc
pdns/dnspcap2calidns.cc
pdns/dnspcap2protobuf.cc
pdns/dnsproxy.cc
pdns/dnsreplay.cc
pdns/dnstcpbench.cc
pdns/dynlistener.cc
pdns/dynloader.cc
pdns/dynmessenger.cc
pdns/syncres.cc
pdns/tcpreceiver.cc
pdns/toysdig.cc
pdns/unix_utility.cc

index ed5ba4727e0b0e0d4e198419bbcacb245c65fb7c..62a8b95c12b524b515c566f7ca8be113102b7609 100644 (file)
@@ -321,7 +321,7 @@ void BPFFilter::block(const DNSName& qname, uint16_t qtype)
     }
 
     if (res != 0) {
-      throw std::runtime_error("Error adding blocked qname " + qname.toLogString() + ": " + std::string(strerror(errno)));
+      throw std::runtime_error("Error adding blocked qname " + qname.toLogString() + ": " + stringerror()));
     }
   }
 }
@@ -345,7 +345,7 @@ void BPFFilter::unblock(const DNSName& qname, uint16_t qtype)
       d_qNamesCount--;
     }
     else {
-      throw std::runtime_error("Error removing qname address " + qname.toLogString() + ": " + std::string(strerror(errno)));
+      throw std::runtime_error("Error removing qname address " + qname.toLogString() + ": " + stringerror()));
     }
   }
 }
index 0f11e790fe588132fcce4c69ccea02d6dc235710..cdf44e533d02a838a57ca4f9fe5349ff0dff85b1 100644 (file)
@@ -129,7 +129,7 @@ static void setSocketBuffer(int fd, int optname, uint32_t size)
 
   if (setsockopt(fd, SOL_SOCKET, optname, (char*)&size, sizeof(size)) < 0 ) {
     if (!g_quiet) {
-      cerr<<"Warning: unable to raise socket buffer size to "<<size<<": "<<strerror(errno)<<endl;
+      cerr<<"Warning: unable to raise socket buffer size to "<<size<<": "<<stringerror()<<endl;
     }
   }
 }
@@ -355,7 +355,7 @@ try
 #if HAVE_SCHED_SETSCHEDULER
   if(sched_setscheduler(0, SCHED_FIFO, &param) < 0) {
     if (!g_quiet) {
-      cerr<<"Unable to set SCHED_FIFO: "<<strerror(errno)<<endl;
+      cerr<<"Unable to set SCHED_FIFO: "<<stringerror()<<endl;
     }
   }
 #endif
@@ -434,7 +434,7 @@ try
   if (g_vm.count("plot-file")) {
     plot.open(g_vm["plot-file"].as<string>());
     if (!plot) {
-      cerr<<"Error opening "<<g_vm["plot-file"].as<string>()<<" for writing: "<<strerror(errno)<<endl;
+      cerr<<"Error opening "<<g_vm["plot-file"].as<string>()<<" for writing: "<<stringerror()<<endl;
       return EXIT_FAILURE;
     }
   }
index c78ebd81aa8819e79ec7cab3c6dc8cd6e3e7c633..b661d9137ba3682917bac4c45ab037dd7d59321b 100644 (file)
@@ -227,7 +227,7 @@ struct SendReceiveRes
     pw.getHeader()->qr = 0;
     
     if(::send(d_socket, &*packet.begin(), packet.size(), 0) < 0) {
-      cout<<"Error sending: "<<strerror(errno)<<endl;
+      cout<<"Error sending: "<<stringerror()<<endl;
       d_senderrors++;
     }
     
@@ -387,7 +387,7 @@ void readRESNames(const std::string& fname, map<DNSName, vector<ComboAddress>>&
 {
   ifstream ifs(fname);
   if(!ifs)
-    unixDie("Reading resolved names from "+fname+": "+string(strerror(errno)));
+    unixDie("Reading resolved names from "+fname+": "+stringerror()));
   vector<string> parts;
   string line;
   addrs.clear();
index 63a0d094f52028fdc3a7d90f489b15313cb9eb76..e2b2387b92331df88ee68b138470e21863438d05 100644 (file)
@@ -539,7 +539,7 @@ void mainthread()
         gethostbyname("a.root-servers.net"); // this forces all lookup libraries to be loaded
      Utility::dropGroupPrivs(newuid, newgid);
      if(chroot(::arg()["chroot"].c_str())<0 || chdir("/")<0) {
-       g_log<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror(errno)<<", exiting"<<endl; 
+       g_log<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<stringerror()<<", exiting"<<endl; 
        exit(1);
      }   
      else
index be8af617239e08a44601ff8c92370d11f06875a9..b3b56ca64831c626b3b75d2d0d42daecb5ec00f6 100644 (file)
@@ -24,7 +24,6 @@
 #endif
 #include "packetcache.hh"
 #include "utility.hh"
-#include <errno.h>
 #include "communicator.hh"
 #include <set>
 #include <boost/utility.hpp>
index 35df6dc8fc9940f5e498d409a4cab5659da1ce6d..6b1e2788f4728815ce0cbaf488765405edc21029 100644 (file)
@@ -143,11 +143,12 @@ int DevPollFDMultiplexer::run(struct timeval* now, int timeout)
   dvp.dp_fds = new pollfd[dvp.dp_nfds];
   dvp.dp_timeout = timeout;
   int ret=ioctl(d_devpollfd, DP_POLL, &dvp);
+  int err = errno;
   gettimeofday(now,0); // MANDATORY!
 
-  if(ret < 0 && errno!=EINTR) {
+  if(ret < 0 && err!=EINTR) {
     delete[] dvp.dp_fds;
-    throw FDMultiplexerException("/dev/poll returned error: "+stringerror());
+    throw FDMultiplexerException("/dev/poll returned error: "+stringerror(err));
   }
 
   if(ret < 1) { // thanks AB!
index 79d0d4156d88224d66d1bc1c2d689c61bd99495b..bcbbb3517e69494eee54f861cad58e0bca15fe9c 100644 (file)
@@ -152,7 +152,7 @@ static void dns_random_setup(bool force=false)
     // some systems define getrandom but it does not really work, e.g. because it's
     // not present in kernel.
     if (getrandom(buf, sizeof(buf), 0) == -1) {
-       g_log<<Logger::Warning<<"getrandom() failed: "<<strerror(errno)<<", falling back to " + rdev<<std::endl;
+       g_log<<Logger::Warning<<"getrandom() failed: "<<stringerror()<<", falling back to " + rdev<<std::endl;
        chosen_rng = RNG_URANDOM;
     }
   }
index 8419011661fd5022e8df2547b6c7d906652bcb72..9021d4f7ad7bd29c08bb09ddf6a1dcc6d4eae1a4 100644 (file)
@@ -274,16 +274,18 @@ void TCPClientCollection::addTCPClientThread()
     }
 
     if (!setNonBlocking(pipefds[0])) {
+      int err = errno;
       close(pipefds[0]);
       close(pipefds[1]);
-      errlog("Error setting the TCP thread communication pipe non-blocking: %s", strerror(errno));
+      errlog("Error setting the TCP thread communication pipe non-blocking: %s", strerror(err));
       return;
     }
 
     if (!setNonBlocking(pipefds[1])) {
+      int err = errno;
       close(pipefds[0]);
       close(pipefds[1]);
-      errlog("Error setting the TCP thread communication pipe non-blocking: %s", strerror(errno));
+      errlog("Error setting the TCP thread communication pipe non-blocking: %s", strerror(err));
       return;
     }
   }
@@ -365,7 +367,7 @@ IOState tryRead(int fd, std::vector<uint8_t>& buffer, size_t& pos, size_t toRead
         return IOState::NeedRead;
       }
       else {
-        throw std::runtime_error(std::string("Error while reading message: ") + strerror(errno));
+        throw std::runtime_error(std::string("Error while reading message: ") + stringerror());
       }
     }
 
@@ -1145,7 +1147,7 @@ static void handleIncomingTCPQuery(int pipefd, FDMultiplexer::funcparam_t& param
     if (errno == EAGAIN || errno == EINTR) {
       return;
     }
-    throw std::runtime_error("Error while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mode:" + strerror(errno));
+    throw std::runtime_error("Error while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mode:" + stringerror());
   }
   else if (got != sizeof(citmp)) {
     throw std::runtime_error("Partial read while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mode");
@@ -1261,7 +1263,7 @@ void tcpAcceptorThread(void* p)
       ++cs->tcpCurrentConnections;
 
       if(ci->fd < 0) {
-        throw std::runtime_error((boost::format("accepting new connection on socket: %s") % strerror(errno)).str());
+        throw std::runtime_error((boost::format("accepting new connection on socket: %s") % stringerror()).str());
       }
 
       if(!acl->match(remote)) {
index d5c17029a986ca9f5ebabb205317182dcd1f3a8a..dd5947f645efc58b7ac6d3c42b281357f64528b3 100644 (file)
@@ -480,7 +480,7 @@ static bool sendUDPResponse(int origFD, const char* response, const uint16_t res
     }
     if (res == -1) {
       int err = errno;
-      vinfolog("Error sending response to %s: %s", origRemote.toStringWithPort(), strerror(err));
+      vinfolog("Error sending response to %s: %s", origRemote.toStringWithPort(), stringerror(err));
     }
   }
 
@@ -1657,7 +1657,7 @@ static void MultipleMessagesUDPClientThread(ClientState* cs, LocalHolders& holde
     int msgsGot = recvmmsg(cs->udpFD, msgVec.get(), vectSize, MSG_WAITFORONE | MSG_TRUNC, nullptr);
 
     if (msgsGot <= 0) {
-      vinfolog("Getting UDP messages via recvmmsg() failed with: %s", strerror(errno));
+      vinfolog("Getting UDP messages via recvmmsg() failed with: %s", stringerror());
       continue;
     }
 
@@ -1685,7 +1685,7 @@ static void MultipleMessagesUDPClientThread(ClientState* cs, LocalHolders& holde
       int sent = sendmmsg(cs->udpFD, outMsgVec.get(), msgsToSend, 0);
 
       if (sent < 0 || static_cast<unsigned int>(sent) != msgsToSend) {
-        vinfolog("Error sending responses with sendmmsg() (%d on %u): %s", sent, msgsToSend, strerror(errno));
+        vinfolog("Error sending responses with sendmmsg() (%d on %u): %s", sent, msgsToSend, stringerror());
       }
     }
 
@@ -2098,22 +2098,22 @@ static void bindAny(int af, int sock)
 
 #ifdef IP_FREEBIND
   if (setsockopt(sock, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) < 0)
-    warnlog("Warning: IP_FREEBIND setsockopt failed: %s", strerror(errno));
+    warnlog("Warning: IP_FREEBIND setsockopt failed: %s", stringerror());
 #endif
 
 #ifdef IP_BINDANY
   if (af == AF_INET)
     if (setsockopt(sock, IPPROTO_IP, IP_BINDANY, &one, sizeof(one)) < 0)
-      warnlog("Warning: IP_BINDANY setsockopt failed: %s", strerror(errno));
+      warnlog("Warning: IP_BINDANY setsockopt failed: %s", stringerror());
 #endif
 #ifdef IPV6_BINDANY
   if (af == AF_INET6)
     if (setsockopt(sock, IPPROTO_IPV6, IPV6_BINDANY, &one, sizeof(one)) < 0)
-      warnlog("Warning: IPV6_BINDANY setsockopt failed: %s", strerror(errno));
+      warnlog("Warning: IPV6_BINDANY setsockopt failed: %s", stringerror());
 #endif
 #ifdef SO_BINDANY
   if (setsockopt(sock, SOL_SOCKET, SO_BINDANY, &one, sizeof(one)) < 0)
-    warnlog("Warning: SO_BINDANY setsockopt failed: %s", strerror(errno));
+    warnlog("Warning: SO_BINDANY setsockopt failed: %s", stringerror());
 #endif
 }
 
@@ -2122,11 +2122,11 @@ static void dropGroupPrivs(gid_t gid)
   if (gid) {
     if (setgid(gid) == 0) {
       if (setgroups(0, NULL) < 0) {
-        warnlog("Warning: Unable to drop supplementary gids: %s", strerror(errno));
+        warnlog("Warning: Unable to drop supplementary gids: %s", stringerror());
       }
     }
     else {
-      warnlog("Warning: Unable to set group ID to %d: %s", gid, strerror(errno));
+      warnlog("Warning: Unable to set group ID to %d: %s", gid, stringerror());
     }
   }
 }
@@ -2135,7 +2135,7 @@ static void dropUserPrivs(uid_t uid)
 {
   if(uid) {
     if(setuid(uid) < 0) {
-      warnlog("Warning: Unable to set user ID to %d: %s", uid, strerror(errno));
+      warnlog("Warning: Unable to set user ID to %d: %s", uid, stringerror());
     }
   }
 }
@@ -2252,7 +2252,7 @@ static void setUpLocalBind(std::unique_ptr<ClientState>& cs)
 #ifdef SO_BINDTODEVICE
     int res = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, itf.c_str(), itf.length());
     if (res != 0) {
-      warnlog("Error setting up the interface on local address '%s': %s", cs->local.toStringWithPort(), strerror(errno));
+      warnlog("Error setting up the interface on local address '%s': %s", cs->local.toStringWithPort(), stringerror());
     }
 #else
     if (warn) {
index ac752f506fc7439a002a2c480b2e03780e72b8e4..e1050c6532a00372b483ad994d1e65a9007e522f 100644 (file)
@@ -28,7 +28,6 @@
 #include <sys/types.h>
 #include <iostream>  
 #include <string>
-#include <errno.h>
 #include <boost/tokenizer.hpp>
 #include <boost/functional/hash.hpp>
 #include <boost/algorithm/string.hpp>
index c64b1ae3d21e72a9c9687212733d843a28f82bb1..7348010ab9f860f9039b5543d29631700a239832 100644 (file)
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
     ofstream fp(argv[2]);
 
     if (!fp) {
-      cerr<<"Error opening output file "<<argv[2]<<": "<<strerror(errno)<<endl;
+      cerr<<"Error opening output file "<<argv[2]<<": "<<stringerror()<<endl;
       exit(EXIT_FAILURE);
     }
 
index 9d0f19ad75174a14ff1ba3d2ae1423d764809957..22482737b06ee2764e1f15b2ff4255f7d1307a32 100644 (file)
@@ -66,7 +66,7 @@ try {
 
   FILE* fp = fopen(argv[2], "w");
   if (!fp) {
-    cerr<<"Error opening output file "<<argv[2]<<": "<<strerror(errno)<<endl;
+    cerr<<"Error opening output file "<<argv[2]<<": "<<stringerror()<<endl;
     exit(EXIT_FAILURE);
   }
 
index 69e5fd1b56e4f856e44f8e9e8662db7836c31825..017a59b034ddf84b9a16da232559eeb5ccd3ee15 100644 (file)
@@ -27,7 +27,6 @@
 #include "dnsproxy.hh"
 #include "pdnsexception.hh"
 #include <sys/types.h>
-#include <errno.h>
 #include "dns.hh"
 #include "logger.hh"
 #include "statbag.hh"
@@ -50,7 +49,7 @@ DNSProxy::DNSProxy(const string &remote)
   d_remote = ComboAddress(addresses[0], 53);
 
   if((d_sock=socket(d_remote.sin4.sin_family, SOCK_DGRAM,0))<0) {
-    throw PDNSException(string("socket: ")+strerror(errno));
+    throw PDNSException(string("socket: ")+stringerror());
   }
 
   ComboAddress local;
@@ -71,7 +70,7 @@ DNSProxy::DNSProxy(const string &remote)
   if(n==10) {
     closesocket(d_sock);
     d_sock=-1;
-    throw PDNSException(string("binding dnsproxy socket: ")+strerror(errno));
+    throw PDNSException(string("binding dnsproxy socket: ")+stringerror());
   }
 
   if(connect(d_sock, (sockaddr *)&d_remote, d_remote.getSocklen())<0) {
@@ -286,9 +285,10 @@ void DNSProxy::mainloop(void)
         if(i->second.anyLocal) {
           addCMsgSrcAddr(&msgh, cbuf, i->second.anyLocal.get_ptr(), 0);
         }
-        if(sendmsg(i->second.outsock, &msgh, 0) < 0)
-          g_log<<Logger::Warning<<"dnsproxy.cc: Error sending reply with sendmsg (socket="<<i->second.outsock<<"): "<<strerror(errno)<<endl;
-
+        if(sendmsg(i->second.outsock, &msgh, 0) < 0) {
+          int err = errno;
+          g_log<<Logger::Warning<<"dnsproxy.cc: Error sending reply with sendmsg (socket="<<i->second.outsock<<"): "<<stringerror(err)<<endl;
+        }
         i->second.created=0;
       }
     }
index aa0f4e1c595e9ae8fbe2b2751a5fe44cf6b2ea9e..6043c02620d8443934d36197092c6878a69052f1 100644 (file)
@@ -175,7 +175,7 @@ void setSocketBuffer(int fd, int optname, uint32_t size)
   }
 
   if (setsockopt(fd, SOL_SOCKET, optname, (char*)&size, sizeof(size)) < 0 )
-    cerr<<"Warning: unable to raise socket buffer size to "<<size<<": "<<strerror(errno)<<endl;
+    cerr<<"Warning: unable to raise socket buffer size to "<<size<<": "<<stringerror()<<endl;
 }
 
 static void setSocketReceiveBuffer(int fd, uint32_t size)
index d69b6c6866c030de969fb679203031ca03d7598c..596d62ae3f6cd99c1263f0dfe47bf48129045e1d 100644 (file)
@@ -108,10 +108,10 @@ try
   Socket sock(g_dest.sin4.sin_family, SOCK_STREAM);
   int tmp=1;
   if(setsockopt(sock.getHandle(),SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) 
-    throw runtime_error("Unable to set socket reuse: "+string(strerror(errno)));
+    throw runtime_error("Unable to set socket reuse: "+stringerror());
     
   if(g_tcpNoDelay && setsockopt(sock.getHandle(), IPPROTO_TCP, TCP_NODELAY,(char*)&tmp,sizeof tmp)<0) 
-    throw runtime_error("Unable to set socket no delay: "+string(strerror(errno)));
+    throw runtime_error("Unable to set socket no delay: "+stringerror());
 
   sock.connect(g_dest);
   uint16_t len = htons(packet.size());
index 28d11f32e3c0d1993899105d99aa4cd5b4d5860f..59776a39bf33977bd9da1e844a910ba4d3878ae9 100644 (file)
@@ -34,7 +34,6 @@
 
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <errno.h>
 #include <iostream>
 #include <sstream>
 #include <sys/types.h>
@@ -72,21 +71,21 @@ void DynListener::createSocketAndBind(int family, struct sockaddr*local, size_t
 
   if(d_s < 0) {
     if (family == AF_UNIX)
-      g_log<<Logger::Error<<"Unable to create control socket at '"<<((struct sockaddr_un*)local)->sun_path<<"', reason: "<<strerror(errno)<<endl;
+      g_log<<Logger::Error<<"Unable to create control socket at '"<<((struct sockaddr_un*)local)->sun_path<<"', reason: "<<stringerror()<<endl;
     else
-      g_log<<Logger::Error<<"Unable to create control socket on '"<<((ComboAddress *)local)->toStringWithPort()<<"', reason: "<<strerror(errno)<<endl;
+      g_log<<Logger::Error<<"Unable to create control socket on '"<<((ComboAddress *)local)->toStringWithPort()<<"', reason: "<<stringerror()<<endl;
     exit(1);
   }
   
   int tmp=1;
   if(setsockopt(d_s,SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0)
-    throw PDNSException(string("Setsockopt failed on control socket: ")+strerror(errno));
+    throw PDNSException(string("Setsockopt failed on control socket: ")+stringerror());
     
   if(bind(d_s, local, len) < 0) {
     if (family == AF_UNIX)
-      g_log<<Logger::Critical<<"Unable to bind to control socket at '"<<((struct sockaddr_un*)local)->sun_path<<"', reason: "<<strerror(errno)<<endl;
+      g_log<<Logger::Critical<<"Unable to bind to control socket at '"<<((struct sockaddr_un*)local)->sun_path<<"', reason: "<<stringerror()<<endl;
     else
-      g_log<<Logger::Critical<<"Unable to bind to control socket on '"<<((ComboAddress *)local)->toStringWithPort()<<"', reason: "<<strerror(errno)<<endl;
+      g_log<<Logger::Critical<<"Unable to bind to control socket on '"<<((ComboAddress *)local)->toStringWithPort()<<"', reason: "<<stringerror()<<endl;
     exit(1);
   }
 }
@@ -120,7 +119,7 @@ void DynListener::listenOnUnixDomain(const string& fname)
   }
   int err=unlink(fname.c_str());
   if(err < 0 && errno!=ENOENT) {
-    g_log<<Logger::Critical<<"Unable to remove (previous) controlsocket at '"<<fname<<"': "<<strerror(errno)<<endl;
+    g_log<<Logger::Critical<<"Unable to remove (previous) controlsocket at '"<<fname<<"': "<<stringerror()<<endl;
     exit(1);
   }
 
@@ -134,9 +133,9 @@ void DynListener::listenOnUnixDomain(const string& fname)
   d_socketname=fname;
   if(!arg()["setgid"].empty()) {
     if(chmod(fname.c_str(),0660)<0)
-      g_log<<Logger::Error<<"Unable to change group access mode of controlsocket at '"<<fname<<"', reason: "<<strerror(errno)<<endl;
+      g_log<<Logger::Error<<"Unable to change group access mode of controlsocket at '"<<fname<<"', reason: "<<stringerror()<<endl;
     if(chown(fname.c_str(),static_cast<uid_t>(-1), strToGID(arg()["setgid"]))<0)
-      g_log<<Logger::Error<<"Unable to change group ownership of controlsocket at '"<<fname<<"', reason: "<<strerror(errno)<<endl;
+      g_log<<Logger::Error<<"Unable to change group ownership of controlsocket at '"<<fname<<"', reason: "<<stringerror()<<endl;
   }
   
   listen(d_s, 10);
@@ -231,7 +230,7 @@ string DynListener::getLine()
       d_client=accept(d_s,(sockaddr*)&remote,&remlen);
       if(d_client<0) {
         if(errno!=EINTR)
-          g_log<<Logger::Error<<"Unable to accept controlsocket connection ("<<d_s<<"): "<<strerror(errno)<<endl;
+          g_log<<Logger::Error<<"Unable to accept controlsocket connection ("<<d_s<<"): "<<stringerror()<<endl;
         continue;
       }
 
@@ -245,7 +244,7 @@ string DynListener::getLine()
       std::shared_ptr<FILE> fp=std::shared_ptr<FILE>(fdopen(dup(d_client), "r"), fclose);
       if(d_tcp) {
         if(!fgets(&mesg[0], mesg.size(), fp.get())) {
-          g_log<<Logger::Error<<"Unable to receive password from controlsocket ("<<d_client<<"): "<<strerror(errno)<<endl;
+          g_log<<Logger::Error<<"Unable to receive password from controlsocket ("<<d_client<<"): "<<stringerror()<<endl;
           close(d_client);
           continue;
         }
@@ -262,7 +261,7 @@ string DynListener::getLine()
       errno=0;
       if(!fgets(&mesg[0], mesg.size(), fp.get())) {
         if(errno)
-          g_log<<Logger::Error<<"Unable to receive line from controlsocket ("<<d_client<<"): "<<strerror(errno)<<endl;
+          g_log<<Logger::Error<<"Unable to receive line from controlsocket ("<<d_client<<"): "<<stringerror()<<endl;
         close(d_client);
         continue;
       }
index 23bb80b7d180a2b5d1627608a988e30d08509823..7654d6a026aabeb44d55461e5e749886f478d8ae 100644 (file)
@@ -27,7 +27,6 @@
 #include <cstring>
 #include <cstdlib>
 #include <unistd.h>
-#include <errno.h>
 #include <climits>
 #include <string>
 #include <map>
index 7397e51b3f5cb3707db48faadbc715305509cf47..c9314085dc31d6656663141e3489474aba4dd6d9 100644 (file)
@@ -27,7 +27,6 @@
 #include "utility.hh"
 #include <cstdlib>
 #include <cstring>
-#include <cerrno>
 #include <iostream>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -40,7 +39,7 @@ DynMessenger::DynMessenger(const string &fname,
   setCloseOnExec(d_s);
   
   if(d_s<0) {
-    throw PDNSException(string("socket")+strerror(errno));
+    throw PDNSException(string("socket")+stringerror());
   }
 
   try {
@@ -80,7 +79,7 @@ DynMessenger::DynMessenger(const ComboAddress& remote,
   setCloseOnExec(d_s);
  
   if(d_s<0) {
-    throw PDNSException(string("socket")+strerror(errno));
+    throw PDNSException(string("socket")+stringerror());
   }
 
   try {
@@ -97,9 +96,9 @@ DynMessenger::DynMessenger(const ComboAddress& remote,
     int ret = Utility::timed_connect(d_s, (sockaddr*)&remote, remote.getSocklen(), timeout_sec, timeout_usec);
 
     if (ret == 0)
-      throw TimeoutException("Unable to connect to remote '"+remote.toStringWithPort()+"': "+string(strerror(errno)));
+      throw TimeoutException("Unable to connect to remote '"+remote.toStringWithPort()+"': "+stringerror());
     else if (ret < 0)
-      throw PDNSException("Unable to connect to remote '"+remote.toStringWithPort()+"': "+string(strerror(errno)));
+      throw PDNSException("Unable to connect to remote '"+remote.toStringWithPort()+"': "+stringerror());
 
     string login=secret+"\n";
     writen2(d_s, login);
@@ -139,9 +138,9 @@ string DynMessenger::receive() const
     retlen=recv(d_s,buffer,sizeof(buffer),0);
     if(retlen<0) {
       if (errno == EAGAIN)
-        throw TimeoutException("Error from remote in receive(): " + string(strerror(errno)));
+        throw TimeoutException("Error from remote in receive(): " + stringerror());
       else
-        throw PDNSException("Error from remote in receive(): " + string(strerror(errno)));
+        throw PDNSException("Error from remote in receive(): " + stringerror());
     }
 
     answer.append(buffer,retlen);
index a9d40cab8be647bf3d7747c99f244b62f4665ce6..24100abb45f19da32d39e06b952c408cee6edf78 100644 (file)
@@ -3104,7 +3104,8 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname,
       /* -1 means server unreachable */
       s_unreachables++;
       d_unreachables++;
-      LOG(prefix<<qname<<": error resolving from "<<remoteIP.toString()<< (doTCP ? " over TCP" : "") <<", possible error: "<<strerror(errno)<< endl);
+      // XXX questionable use of errno
+      LOG(prefix<<qname<<": error resolving from "<<remoteIP.toString()<< (doTCP ? " over TCP" : "") <<", possible error: "<<stringerror()<< endl);
     }
 
     if(resolveret != -2 && !chained && !dontThrottle) {
index acdfbb1b72b2f162bed131817be42b7fd831c71e..c512b8702be872e2b1831deb1d37aff8de4e71a2 100644 (file)
@@ -1229,7 +1229,7 @@ TCPNameserver::TCPNameserver()
 #ifdef TCP_FASTOPEN
       int fastOpenQueueSize = ::arg().asNum("tcp-fast-open");
       if (setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) {
-        g_log<<Logger::Error<<"Failed to enable TCP Fast Open for listening socket: "<<strerror(errno)<<endl;
+        g_log<<Logger::Error<<"Failed to enable TCP Fast Open for listening socket: "<<stringerror()<<endl;
       }
 #else
       g_log<<Logger::Warning<<"TCP Fast Open configured but not supported for listening socket"<<endl;
@@ -1240,12 +1240,13 @@ TCPNameserver::TCPNameserver()
        Utility::setBindAny(AF_INET, s);
 
     if(::bind(s, (sockaddr*)&local, local.getSocklen())<0) {
+      int err = errno;
       close(s);
-      if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-address-nonexist-fail") ) {
+      if( err == EADDRNOTAVAIL && ! ::arg().mustDo("local-address-nonexist-fail") ) {
         g_log<<Logger::Error<<"IPv4 Address " << *laddr << " does not exist on this server - skipping TCP bind" << endl;
         continue;
       } else {
-        g_log<<Logger::Error<<"Unable to bind to TCP socket " << *laddr << ": "<<strerror(errno)<<endl;
+        g_log<<Logger::Error<<"Unable to bind to TCP socket " << *laddr << ": "<<stringerror(err)<<endl;
         throw PDNSException("Unable to bind to TCP socket");
       }
     }
@@ -1281,7 +1282,7 @@ TCPNameserver::TCPNameserver()
 #ifdef TCP_FASTOPEN
       int fastOpenQueueSize = ::arg().asNum("tcp-fast-open");
       if (setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) {
-        g_log<<Logger::Error<<"Failed to enable TCP Fast Open for listening socket: "<<strerror(errno)<<endl;
+        g_log<<Logger::Error<<"Failed to enable TCP Fast Open for listening socket: "<<stringerror()<<endl;
       }
 #else
       g_log<<Logger::Warning<<"TCP Fast Open configured but not supported for listening socket"<<endl;
@@ -1291,15 +1292,16 @@ TCPNameserver::TCPNameserver()
     if( ::arg().mustDo("non-local-bind") )
        Utility::setBindAny(AF_INET6, s);
     if(setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &tmp, sizeof(tmp)) < 0) {
-      g_log<<Logger::Error<<"Failed to set IPv6 socket to IPv6 only, continuing anyhow: "<<strerror(errno)<<endl;
+      g_log<<Logger::Error<<"Failed to set IPv6 socket to IPv6 only, continuing anyhow: "<<stringerror()<<endl;
     }
     if(bind(s, (const sockaddr*)&local, local.getSocklen())<0) {
+      int err = errno;
       close(s);
-      if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-ipv6-nonexist-fail") ) {
+      if( err == EADDRNOTAVAIL && ! ::arg().mustDo("local-ipv6-nonexist-fail") ) {
         g_log<<Logger::Error<<"IPv6 Address " << *laddr << " does not exist on this server - skipping TCP bind" << endl;
         continue;
       } else {
-        g_log<<Logger::Error<<"Unable to bind to TCPv6 socket" << *laddr << ": "<<strerror(errno)<<endl;
+        g_log<<Logger::Error<<"Unable to bind to TCPv6 socket" << *laddr << ": "<<strerror(err)<<endl;
         throw PDNSException("Unable to bind to TCPv6 socket");
       }
     }
@@ -1340,9 +1342,10 @@ void TCPNameserver::thread()
           addrlen=remote.getSocklen();
 
           if((fd=accept(sock, (sockaddr*)&remote, &addrlen))<0) {
-            g_log<<Logger::Error<<"TCP question accept error: "<<strerror(errno)<<endl;
+            int err = errno;
+            g_log<<Logger::Error<<"TCP question accept error: "<<stringerror(err)<<endl;
             
-            if(errno==EMFILE) {
+            if(err==EMFILE) {
               g_log<<Logger::Error<<"TCP handler out of filedescriptors, exiting, won't recover from this"<<endl;
               _exit(1);
             }
@@ -1366,8 +1369,9 @@ void TCPNameserver::thread()
             if(room<1)
               g_log<<Logger::Warning<<"Limit of simultaneous TCP connections reached - raise max-tcp-connections"<<endl;
 
-            if(pthread_create(&tid, 0, &doConnection, reinterpret_cast<void*>(fd))) {
-              g_log<<Logger::Error<<"Error creating thread: "<<stringerror()<<endl;
+            int err;
+            if((err = pthread_create(&tid, 0, &doConnection, reinterpret_cast<void*>(fd)))) {
+              g_log<<Logger::Error<<"Error creating thread: "<<stringerror(err)<<endl;
               d_connectionroom_sem->post();
               close(fd);
               decrementClientCount(remote);
index 82fba8763afbac36fee6541af81da942b299b926..4c65161bc7e121b983f3a7488d5a56cc16972ce6 100644 (file)
@@ -51,7 +51,7 @@ public:
     
     int bread=d_rsock.read((char *) &len, 2);
     if( bread <0)
-      throw PDNSException("tcp read failed: "+std::string(strerror(errno)));
+      throw PDNSException("tcp read failed: "+stringerror());
     if(bread != 2) 
       throw PDNSException("EOF on TCP read");
 
@@ -63,7 +63,7 @@ public:
       numread=d_rsock.read(creply+n, len-n);
       if(numread<0) {
         delete[] creply;
-        throw PDNSException("tcp read failed: "+std::string(strerror(errno)));
+        throw PDNSException("tcp read failed: "+stringerror());
       }
       n+=numread;
     }
index 3287711b13699de146e094ed31a8790cba7a117e..4cef1e5709404dbc0acb24f1dfaa9ad8a3dd8419 100644 (file)
@@ -84,22 +84,22 @@ void Utility::setBindAny(int af, sock_t sock)
   (void) one; // avoids 'unused var' warning on systems that have none of the defines checked below
 #ifdef IP_FREEBIND
   if (setsockopt(sock, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) < 0)
-      g_log<<Logger::Warning<<"Warning: IP_FREEBIND setsockopt failed: "<<strerror(errno)<<endl;
+      g_log<<Logger::Warning<<"Warning: IP_FREEBIND setsockopt failed: "<<stringerror()<<endl;
 #endif
 
 #ifdef IP_BINDANY
   if (af == AF_INET)
     if (setsockopt(sock, IPPROTO_IP, IP_BINDANY, &one, sizeof(one)) < 0)
-      g_log<<Logger::Warning<<"Warning: IP_BINDANY setsockopt failed: "<<strerror(errno)<<endl;
+      g_log<<Logger::Warning<<"Warning: IP_BINDANY setsockopt failed: "<<stringerror()<<endl;
 #endif
 #ifdef IPV6_BINDANY
   if (af == AF_INET6)
     if (setsockopt(sock, IPPROTO_IPV6, IPV6_BINDANY, &one, sizeof(one)) < 0)
-      g_log<<Logger::Warning<<"Warning: IPV6_BINDANY setsockopt failed: "<<strerror(errno)<<endl;
+      g_log<<Logger::Warning<<"Warning: IPV6_BINDANY setsockopt failed: "<<stringerror()<<endl;
 #endif
 #ifdef SO_BINDANY
   if (setsockopt(sock, SOL_SOCKET, SO_BINDANY, &one, sizeof(one)) < 0)
-      g_log<<Logger::Warning<<"Warning: SO_BINDANY setsockopt failed: "<<strerror(errno)<<endl;
+      g_log<<Logger::Warning<<"Warning: SO_BINDANY setsockopt failed: "<<stringerror()<<endl;
 #endif
 }