From a702a96ce10e4110da9c176e83fa14b01bec789b Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 26 Jun 2019 16:55:19 +0200 Subject: [PATCH] Another batch --- pdns/bpf-filter.cc | 4 ++-- pdns/calidns.cc | 6 +++--- pdns/comfun.cc | 4 ++-- pdns/common_startup.cc | 2 +- pdns/communicator.cc | 1 - pdns/devpollmplexer.cc | 5 +++-- pdns/dns_random.cc | 2 +- pdns/dnsdist-tcp.cc | 12 +++++++----- pdns/dnsdist.cc | 22 +++++++++++----------- pdns/dnspacket.cc | 1 - pdns/dnspcap2calidns.cc | 2 +- pdns/dnspcap2protobuf.cc | 2 +- pdns/dnsproxy.cc | 12 ++++++------ pdns/dnsreplay.cc | 2 +- pdns/dnstcpbench.cc | 4 ++-- pdns/dynlistener.cc | 23 +++++++++++------------ pdns/dynloader.cc | 1 - pdns/dynmessenger.cc | 13 ++++++------- pdns/syncres.cc | 3 ++- pdns/tcpreceiver.cc | 26 +++++++++++++++----------- pdns/toysdig.cc | 4 ++-- pdns/unix_utility.cc | 8 ++++---- 22 files changed, 81 insertions(+), 78 deletions(-) diff --git a/pdns/bpf-filter.cc b/pdns/bpf-filter.cc index ed5ba4727e0b..62a8b95c12b5 100644 --- a/pdns/bpf-filter.cc +++ b/pdns/bpf-filter.cc @@ -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())); } } } diff --git a/pdns/calidns.cc b/pdns/calidns.cc index 0f11e790fe58..cdf44e533d02 100644 --- a/pdns/calidns.cc +++ b/pdns/calidns.cc @@ -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 "<()); if (!plot) { - cerr<<"Error opening "<()<<" for writing: "<()<<" for writing: "<qr = 0; if(::send(d_socket, &*packet.begin(), packet.size(), 0) < 0) { - cout<<"Error sending: "<>& { ifstream ifs(fname); if(!ifs) - unixDie("Reading resolved names from "+fname+": "+string(strerror(errno))); + unixDie("Reading resolved names from "+fname+": "+stringerror())); vector parts; string line; addrs.clear(); diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 63a0d094f520..e2b2387b9233 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -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< #include "communicator.hh" #include #include diff --git a/pdns/devpollmplexer.cc b/pdns/devpollmplexer.cc index 35df6dc8fc99..6b1e2788f472 100644 --- a/pdns/devpollmplexer.cc +++ b/pdns/devpollmplexer.cc @@ -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! diff --git a/pdns/dns_random.cc b/pdns/dns_random.cc index 79d0d4156d88..bcbbb3517e69 100644 --- a/pdns/dns_random.cc +++ b/pdns/dns_random.cc @@ -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<& 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)) { diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index d5c17029a986..dd5947f645ef 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -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(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& 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) { diff --git a/pdns/dnspacket.cc b/pdns/dnspacket.cc index ac752f506fc7..e1050c6532a0 100644 --- a/pdns/dnspacket.cc +++ b/pdns/dnspacket.cc @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/pdns/dnspcap2calidns.cc b/pdns/dnspcap2calidns.cc index c64b1ae3d21e..7348010ab9f8 100644 --- a/pdns/dnspcap2calidns.cc +++ b/pdns/dnspcap2calidns.cc @@ -65,7 +65,7 @@ int main(int argc, char **argv) ofstream fp(argv[2]); if (!fp) { - cerr<<"Error opening output file "< -#include #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<second.outsock, &msgh, 0) < 0) { + int err = errno; + g_log<second.created=0; } } diff --git a/pdns/dnsreplay.cc b/pdns/dnsreplay.cc index aa0f4e1c595e..6043c02620d8 100644 --- a/pdns/dnsreplay.cc +++ b/pdns/dnsreplay.cc @@ -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 "< #include -#include #include #include #include @@ -72,21 +71,21 @@ void DynListener::createSocketAndBind(int family, struct sockaddr*local, size_t if(d_s < 0) { if (family == AF_UNIX) - g_log<sun_path<<"', reason: "<sun_path<<"', reason: "<toStringWithPort()<<"', reason: "<toStringWithPort()<<"', reason: "<sun_path<<"', reason: "<sun_path<<"', reason: "<toStringWithPort()<<"', reason: "<toStringWithPort()<<"', reason: "<(-1), strToGID(arg()["setgid"]))<0) - g_log< fp=std::shared_ptr(fdopen(dup(d_client), "r"), fclose); if(d_tcp) { if(!fgets(&mesg[0], mesg.size(), fp.get())) { - g_log< #include #include -#include #include #include #include diff --git a/pdns/dynmessenger.cc b/pdns/dynmessenger.cc index 7397e51b3f5c..c9314085dc31 100644 --- a/pdns/dynmessenger.cc +++ b/pdns/dynmessenger.cc @@ -27,7 +27,6 @@ #include "utility.hh" #include #include -#include #include #include #include @@ -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); diff --git a/pdns/syncres.cc b/pdns/syncres.cc index a9d40cab8be6..24100abb45f1 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -3104,7 +3104,8 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname, /* -1 means server unreachable */ s_unreachables++; d_unreachables++; - LOG(prefix<(fd))) { - g_log<(fd)))) { + g_log<post(); close(fd); decrementClientCount(remote); diff --git a/pdns/toysdig.cc b/pdns/toysdig.cc index 82fba8763afb..4c65161bc7e1 100644 --- a/pdns/toysdig.cc +++ b/pdns/toysdig.cc @@ -51,7 +51,7 @@ class TCPResolver : public boost::noncopyable 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 @@ class TCPResolver : public boost::noncopyable 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; } diff --git a/pdns/unix_utility.cc b/pdns/unix_utility.cc index 3287711b1369..4cef1e570940 100644 --- a/pdns/unix_utility.cc +++ b/pdns/unix_utility.cc @@ -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<