]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add an error(int errno, msg) method
authorOtto <otto.moerbeek@open-xchange.com>
Wed, 28 Apr 2021 11:16:44 +0000 (13:16 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 28 Apr 2021 11:16:44 +0000 (13:16 +0200)
pdns/recursordist/logging.cc
pdns/recursordist/logging.hh
pdns/recursordist/logr.hh
pdns/rpzloader.cc

index ad796a8feaa79fde4b9db76676ac26a11e6aa75c..2b172d917e012c1953e0ee8c78dcef244f4b63d6 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "logging.hh"
+#include <string>
 
 namespace Logging
 {
@@ -59,6 +60,11 @@ namespace Logging
     _callback(std::move(entry));
   }
 
+  void Logger::error(int err, const std::string& msg)
+  {
+    logMessage(msg, std::string(std::strerror(err)));
+  }
+
   void Logger::error(const std::string& err, const std::string& msg)
   {
     logMessage(msg, err);
index 825ab36d03523e7bef3b8be7e0e6ff8a1c6ab190..246611023bdadbf0de25bf12b553041a7dfadbb3 100644 (file)
@@ -71,6 +71,7 @@ namespace Logging {
   public:
     virtual bool enabled();
     virtual void info(const std::string& msg);
+    virtual void error(int err, const std::string& msg);
     virtual void error(const std::string& err, const std::string& msg);
     virtual std::shared_ptr<Logr::Logger> v(size_t level);
 
index 2345c3f1fdfd33532944563555296e3288bc9e1f..7a88fc06b37aa2b3b0e01123a8cad3723b7c59c6 100644 (file)
@@ -56,6 +56,7 @@ namespace Logr {
     // while the err field should be used to attach the actual error that
     // triggered this log line, if present.
     virtual void error(const std::string& err, const std::string& msg) = 0;
+    virtual void error(int err, const std::string& msg) = 0;
 
     // V returns an Logger value for a specific verbosity level, relative to
     // this Logger.  In other words, V values are additive.  V higher verbosity
index 3c27c1cd968b56c180b064494b70f29ed3bf2f83..b387cd56741e9ea4e44b8c206dc286ecebfd4efe 100644 (file)
@@ -313,7 +313,7 @@ static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptr<DNSFil
   std::string temp = dumpZoneFileName + "XXXXXX";
   int fd = mkstemp(&temp.at(0));
   if (fd < 0) {
-    logger->error(strerror(errno), "Unable to create temporary file");
+    logger->error(errno, "Unable to create temporary file");
     return false;
   }
 
@@ -321,7 +321,7 @@ static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptr<DNSFil
   if (!fp) {
     int err = errno;
     close(fd);
-    logger->error(stringerror(err), "Unable to open file pointer");
+    logger->error(err, "Unable to open file pointer");
     return false;
   }
   fd = -1;
@@ -335,24 +335,24 @@ static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptr<DNSFil
   }
 
   if (fflush(fp.get()) != 0) {
-    logger->error(stringerror(), "Error while flushing the content of the RPZ");
+    logger->error(errno, "Error while flushing the content of the RPZ");
     return false;
   }
 
   if (fsync(fileno(fp.get())) != 0) {
-    logger->error(stringerror(), "Error while syncing the content of the RPZ");
+    logger->error(errno, "Error while syncing the content of the RPZ");
     return false;
   }
 
   if (fclose(fp.release()) != 0) {
-    logger->error(stringerror(), "Error while writing the content of the RPZ");
+    logger->error(errno, "Error while writing the content of the RPZ");
     return false;
   }
 
   if (rename(temp.c_str(), dumpZoneFileName.c_str()) != 0) {
     logger
       ->withValues("destination_file", Logging::Loggable(dumpZoneFileName))
-      ->error(stringerror(), "Error while moving the content of the RPZ");
+      ->error(errno, "Error while moving the content of the RPZ");
     return false;
   }