X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=pdns%2Fmisc.cc;h=9b6eea36d56b2668367ed46974fb98a7b58805e5;hb=381b365c13e9280cba479a2374f259b9eee824d7;hp=10f799a74f4567c185e125a8824211b5ff31bbf8;hpb=5e1f23ca6486ea8ac59a55a2921d978e1c69a40c;p=thirdparty%2Fpdns.git diff --git a/pdns/misc.cc b/pdns/misc.cc index 10f799a74f..9b6eea36d5 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -202,7 +202,7 @@ string nowTime() // YYYY-mm-dd HH:MM:SS TZOFF strftime(buffer, sizeof(buffer), "%F %T %z", tm); buffer[sizeof(buffer)-1] = '\0'; - return buffer; + return string(buffer); } uint16_t getShort(const unsigned char *p) @@ -498,7 +498,7 @@ string getHostname() if(gethostname(tmp, MAXHOSTNAMELEN)) return "UNKNOWN"; - return tmp; + return string(tmp); } string itoa(int i) @@ -571,7 +571,7 @@ string U32ToIP(uint32_t val) (val >> 16)&0xff, (val >> 8)&0xff, (val )&0xff); - return tmp; + return string(tmp); } @@ -1101,6 +1101,22 @@ bool isNonBlocking(int sock) return flags & O_NONBLOCK; } +bool setReceiveSocketErrors(int sock, int af) +{ +#ifdef __linux__ + int tmp = 1, ret; + if (af == AF_INET) { + ret = setsockopt(sock, IPPROTO_IP, IP_RECVERR, &tmp, sizeof(tmp)); + } else { + ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVERR, &tmp, sizeof(tmp)); + } + if (ret < 0) { + throw PDNSException(string("Setsockopt failed: ") + strerror(errno)); + } +#endif + return true; +} + // Closes a socket. int closesocket( int socket ) { @@ -1241,7 +1257,27 @@ uint64_t getOpenFileDescriptors(const std::string&) uint64_t getRealMemoryUsage(const std::string&) { #ifdef __linux__ - ifstream ifs("/proc/"+std::to_string(getpid())+"/smaps"); + ifstream ifs("/proc/self/statm"); + if(!ifs) + return 0; + + uint64_t size, resident, shared, text, lib, data; + ifs >> size >> resident >> shared >> text >> lib >> data; + + return data * getpagesize(); +#else + struct rusage ru; + if (getrusage(RUSAGE_SELF, &ru) != 0) + return 0; + return ru.ru_maxrss * 1024; +#endif +} + + +uint64_t getSpecialMemoryUsage(const std::string&) +{ +#ifdef __linux__ + ifstream ifs("/proc/self/smaps"); if(!ifs) return 0; string line;