Skip to content

Commit

Permalink
Another batch
Browse files Browse the repository at this point in the history
  • Loading branch information
omoerbeek committed Jun 26, 2019
1 parent 001f57d commit a702a96
Show file tree
Hide file tree
Showing 22 changed files with 81 additions and 78 deletions.
4 changes: 2 additions & 2 deletions pdns/bpf-filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}
Expand All @@ -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()));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pdns/calidns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pdns/comfun.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion pdns/common_startup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pdns/communicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#endif
#include "packetcache.hh"
#include "utility.hh"
#include <errno.h>
#include "communicator.hh"
#include <set>
#include <boost/utility.hpp>
Expand Down
5 changes: 3 additions & 2 deletions pdns/devpollmplexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion pdns/dns_random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
12 changes: 7 additions & 5 deletions pdns/dnsdist-tcp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)) {
Expand Down
22 changes: 11 additions & 11 deletions pdns/dnsdist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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());
}
}
}
Expand All @@ -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());
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion pdns/dnspacket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnspcap2calidns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion pdns/dnspcap2protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions pdns/dnsproxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsreplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnstcpbench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

0 comments on commit a702a96

Please sign in to comment.