]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: more log (level) fixes
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 29 Sep 2023 09:33:01 +0000 (11:33 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 29 Sep 2023 09:33:01 +0000 (11:33 +0200)
Found while working on a list

pdns/recursordist/lua-recursor4.cc
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/pubsuffixloader.cc
pdns/recursordist/rec-lua-conf.cc
pdns/recursordist/rec-taskqueue.cc
pdns/recursordist/rec-tcp.cc
pdns/recursordist/syncres.cc
pdns/unix_utility.cc

index 04c538025cd58d5c1914d25afb163a6e9d847cd3..6ba031e9e14a76f466744d39d1c73d27d53c8905 100644 (file)
@@ -22,6 +22,7 @@
 #include "lua-recursor4.hh"
 #include <fstream>
 #include "logger.hh"
+#include "logging.hh"
 #include "dnsparser.hh"
 #include "syncres.hh"
 #include "namespaces.hh"
@@ -346,7 +347,8 @@ void RecursorLua4::postPrepareContext()
         }
       }
       catch(std::exception& e) {
-        g_log <<Logger::Error<<e.what()<<endl;
+        SLOG(g_log <<Logger::Error<<e.what()<<endl,
+             g_slog->withName("lua")->error(Logr::Error, e.what(), "Error in call to DNSSuffixMatchGroup:add"));
       }
     }
   );
@@ -501,7 +503,8 @@ void RecursorLua4::getFeatures(Features& features)
 static void warnDrop(const RecursorLua4::DNSQuestion& dq)
 {
   if (dq.rcode == -2) {
-    g_log << Logger::Error << "Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics" << endl;
+    SLOG(g_log << Logger::Error << "Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics" << endl,
+         g_slog->withName("lua")->info(Logr::Error,"Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics"));
     // We *could* set policy here, but that would also mean interfering with rcode and the return code of the hook.
     // So leave it at the error message.
   }
@@ -744,7 +747,8 @@ bool RecursorLua4::genhook(const luacall_t& func, DNSQuestion& dq, int& ret) con
         dq.udpAnswer = std::string(reinterpret_cast<const char*>(p.data()), p.size());
         auto cbFunc = d_lw->readVariable<boost::optional<luacall_t>>(dq.udpCallback).get_value_or(0);
         if (!cbFunc) {
-          g_log << Logger::Error << "Attempted callback for Lua UDP Query/Response which could not be found" << endl;
+          SLOG(g_log << Logger::Error << "Attempted callback for Lua UDP Query/Response which could not be found" << endl,
+               g_slog->withName("lua")->info(Logr::Error, "Attempted callback for Lua UDP Query/Response which could not be found"));
           return false;
         }
         bool result = cbFunc(&dq);
index 3eafd3f69c2d510e89aad371167386f462fe72ca..6ecbce1b78ecb0c096c236710975434fb41870dc 100644 (file)
@@ -1882,7 +1882,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
   }
   catch (const std::exception& e) {
     SLOG(g_log << Logger::Error << "STL error " << makeLoginfo(comboWriter) << ": " << e.what(),
-         resolver.d_slog->error(Logr::Error, e.what(), "Exception in resolver context ", "exception", Logging::Loggable("std::exception")));
+         resolver.d_slog->error(Logr::Error, e.what(), "Exception in resolver context", "exception", Logging::Loggable("std::exception")));
 
     // Luawrapper nests the exception from Lua, so we unnest it here
     try {
@@ -2624,8 +2624,8 @@ void makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log)
 #endif
       if (address.sin6.sin6_family == AF_INET6 && setsockopt(socketFd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one)) < 0) {
         int err = errno;
-        SLOG(g_log << Logger::Error << "Failed to set IPv6 socket to IPv6 only, continuing anyhow: " << stringerror(err) << endl,
-             log->error(Logr::Error, "Failed to set IPv6 socket to IPv6 only, continuing anyhow"));
+        SLOG(g_log << Logger::Warning << "Failed to set IPv6 socket to IPv6 only, continuing anyhow: " << stringerror(err) << endl,
+             log->error(Logr::Warning, "Failed to set IPv6 socket to IPv6 only, continuing anyhow"));
       }
     }
     if (::arg().mustDo("non-local-bind")) {
@@ -2755,7 +2755,7 @@ void distributeAsyncFunction(const string& packet, const pipefunc_t& func)
 {
   if (!RecThreadInfo::self().isDistributor()) {
     SLOG(g_log << Logger::Error << "distributeAsyncFunction() has been called by a worker (" << RecThreadInfo::id() << ")" << endl,
-         g_slog->info(Logr::Error, "distributeAsyncFunction() has been called by a worker")); // tid will be added
+         g_slog->withName("runtime")->info(Logr::Error, "distributeAsyncFunction() has been called by a worker")); // tid will be added
     _exit(1);
   }
 
index ea8b9908d00f7c89b7bc14d8a959e28121e0c28b..3d413d66c9a307400a981c21dde700581b9c214c 100644 (file)
@@ -73,7 +73,7 @@ void initPublicSuffixList(const std::string& file)
     }
     catch (const std::exception& e) {
       SLOG(g_log << Logger::Warning << "Error while loading the Public Suffix List from '" << file << "', falling back to the built-in list: " << e.what() << endl,
-           g_slog->withName("runtime")->error(Logr::Error, e.what(), "Loaded the Public Suffix List", "file", Logging::Loggable(file)));
+           g_slog->withName("runtime")->error(Logr::Error, e.what(), "Error while loading the Public Suffix List", "file", Logging::Loggable(file)));
     }
   }
 
index ec169e45442118ce1fc381f39288af497944fe24..96d12941705d5e85e6197bad77921e7af831a5b3 100644 (file)
@@ -377,13 +377,11 @@ static void rpzPrimary(LuaConfigItems& lci, luaConfigDelayedThreads& delayedThre
   }
   catch (const std::exception& e) {
     SLOG(g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.what() << endl,
-         lci.d_slog->error(Logr::Critical, e.what(), "Exception configuring 'rpzPrimary'", "exception", Logging::Loggable("std::exception")));
-    exit(1); // FIXME proper exit code?
+         lci.d_slog->error(Logr::Error, e.what(), "Exception configuring 'rpzPrimary'", "exception", Logging::Loggable("std::exception")));
   }
   catch (const PDNSException& e) {
     SLOG(g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.reason << endl,
-         lci.d_slog->error(Logr::Critical, e.reason, "Exception configuring 'rpzPrimary'", Logging::Loggable("PDNSException")));
-    exit(1); // FIXME proper exit code?
+         lci.d_slog->error(Logr::Error, e.reason, "Exception configuring 'rpzPrimary'", Logging::Loggable("PDNSException")));
   }
 
   delayedThreads.rpzPrimaryThreads.emplace_back(primaries, defpol, defpolOverrideLocal, maxTTL, zoneIdx, tt, maxReceivedXFRMBytes, localAddress, axfrTimeout, refresh, sr, dumpFile);
index 9997991455b491b72d793d394b007081b19411b6..b5dba064dfa4c8ecd3b509cddf0d981cd2a494be 100644 (file)
@@ -134,23 +134,23 @@ static void resolveInternal(const struct timeval& now, bool logErrors, const pdn
     log->info(Logr::Debug, "done", "rcode", Logging::Loggable(res), "records", Logging::Loggable(ret.size()));
   }
   catch (const std::exception& e) {
-    log->error(Logr::Error, msg, e.what());
+    log->error(Logr::Warning, msg, e.what());
   }
   catch (const PDNSException& e) {
-    log->error(Logr::Error, msg, e.reason);
+    log->error(Logr::Warning, msg, e.reason);
   }
   catch (const ImmediateServFailException& e) {
     if (logErrors) {
-      log->error(Logr::Error, msg, e.reason);
+      log->error(Logr::Warning, msg, e.reason);
     }
   }
   catch (const PolicyHitException& e) {
     if (logErrors) {
-      log->error(Logr::Notice, msg, "PolicyHit");
+      log->error(Logr::Warning, msg, "PolicyHit");
     }
   }
   catch (...) {
-    log->error(Logr::Error, msg, "Unexpectec exception");
+    log->error(Logr::Warning, msg, "Unexpectec exception");
   }
   if (exceptionOccurred) {
     if (task.d_refreshMode) {
@@ -195,14 +195,14 @@ static void tryDoT(const struct timeval& now, bool logErrors, const pdns::Resolv
     log->info(Logr::Debug, "done", "ok", Logging::Loggable(tryOK));
   }
   catch (const std::exception& e) {
-    log->error(Logr::Error, msg, e.what());
+    log->error(Logr::Warning, msg, e.what());
   }
   catch (const PDNSException& e) {
-    log->error(Logr::Error, msg, e.reason);
+    log->error(Logr::Warning, msg, e.reason);
   }
   catch (const ImmediateServFailException& e) {
     if (logErrors) {
-      log->error(Logr::Error, msg, e.reason);
+      log->error(Logr::Warning, msg, e.reason);
     }
   }
   catch (const PolicyHitException& e) {
@@ -211,7 +211,7 @@ static void tryDoT(const struct timeval& now, bool logErrors, const pdns::Resolv
     }
   }
   catch (...) {
-    log->error(Logr::Error, msg, "Unexpected exception");
+    log->error(Logr::Warning, msg, "Unexpected exception");
   }
   if (exceptionOccurred) {
     ++s_resolve_tasks.exceptions;
index ca3c3b3e3687f1ae354a366352b78e3d2b4b2dc3..7d1a8bb3d1038d6b6c33060688eb8b674e8d1d99 100644 (file)
@@ -1114,7 +1114,7 @@ void makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tcpSockets
     if (address.sin6.sin6_family == AF_INET6 && setsockopt(socketFd, IPPROTO_IPV6, IPV6_V6ONLY, &tmp, sizeof(tmp)) < 0) {
       int err = errno;
       SLOG(g_log << Logger::Error << "Failed to set IPv6 socket to IPv6 only, continuing anyhow: " << stringerror(err) << endl,
-           log->error(Logr::Error, err, "Failed to set IPv6 socket to IPv6 only, continuing anyhow"));
+           log->error(Logr::Warning, err, "Failed to set IPv6 socket to IPv6 only, continuing anyhow"));
     }
 
 #ifdef TCP_DEFER_ACCEPT
index 8e8819fb7c26b864418ffcf3aff54f2807d8a96d..253058ecacd994394c62934d12e1c3e9527ba6c4 100644 (file)
@@ -5897,28 +5897,28 @@ int directResolve(const DNSName& qname, const QType qtype, const QClass qclass,
     res = sr.beginResolve(qname, qtype, qclass, ret, 0);
   }
   catch (const PDNSException& e) {
-    SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got pdns exception: " << e.reason << endl,
-         log->error(Logr::Error, e.reason, msg, "exception", Logging::Loggable("PDNSException")));
+    SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got pdns exception: " << e.reason << endl,
+         log->error(Logr::Warning, e.reason, msg, "exception", Logging::Loggable("PDNSException")));
     ret.clear();
   }
   catch (const ImmediateServFailException& e) {
-    SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got ImmediateServFailException: " << e.reason << endl,
-         log->error(Logr::Error, e.reason, msg, "exception", Logging::Loggable("ImmediateServFailException")));
+    SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got ImmediateServFailException: " << e.reason << endl,
+         log->error(Logr::Warning, e.reason, msg, "exception", Logging::Loggable("ImmediateServFailException")));
     ret.clear();
   }
   catch (const PolicyHitException& e) {
-    SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got a policy hit" << endl,
-         log->info(Logr::Error, msg, "exception", Logging::Loggable("PolicyHitException")));
+    SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got a policy hit" << endl,
+         log->info(Logr::Warning, msg, "exception", Logging::Loggable("PolicyHitException")));
     ret.clear();
   }
   catch (const std::exception& e) {
-    SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got STL error: " << e.what() << endl,
-         log->error(Logr::Error, e.what(), msg, "exception", Logging::Loggable("std::exception")));
+    SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got STL error: " << e.what() << endl,
+         log->error(Logr::Warning, e.what(), msg, "exception", Logging::Loggable("std::exception")));
     ret.clear();
   }
   catch (...) {
-    SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got an exception" << endl,
-         log->info(Logr::Error, msg));
+    SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got an exception" << endl,
+         log->info(Logr::Warning, msg));
     ret.clear();
   }
 
index 2fb2d00e07cac50c99f98d70cf9095f96bd7126b..b6b169aa17a9323428e43fb2588523a67db30cc7 100644 (file)
@@ -165,7 +165,7 @@ void Utility::dropGroupPrivs( uid_t uid, gid_t gid )
       if (initgroups(pw->pw_name, gid)<0) {
         int err = errno;
         SLOG(g_log<<Logger::Critical<<"Unable to set supplementary groups: "<<stringerror(err)<<endl,
-             g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to drop supplementary groups"));
+             g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to set supplementary groups"));
         exit(1);
       }
     }
@@ -180,7 +180,7 @@ void Utility::dropUserPrivs( uid_t uid )
     if(setuid(uid)<0) {
       int err = errno;
       SLOG(g_log<<Logger::Critical<<"Unable to set effective user id to "<<uid<<": "<<stringerror(err)<<endl,
-           g_slog->withName("runtime")->error(Logr::Error, err, "Unable to set effective user id", "uid", Logging::Loggable(uid)));
+           g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to set effective user id", "uid", Logging::Loggable(uid)));
       exit(1);
     }
     else {