From b3c8eddedc989e0d9f74ed7b672f3f8c6e4e933b Mon Sep 17 00:00:00 2001 From: Otto Date: Wed, 28 Apr 2021 13:16:44 +0200 Subject: [PATCH] Add an error(int errno, msg) method --- pdns/recursordist/logging.cc | 6 ++++++ pdns/recursordist/logging.hh | 1 + pdns/recursordist/logr.hh | 1 + pdns/rpzloader.cc | 12 ++++++------ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pdns/recursordist/logging.cc b/pdns/recursordist/logging.cc index ad796a8fea..2b172d917e 100644 --- a/pdns/recursordist/logging.cc +++ b/pdns/recursordist/logging.cc @@ -21,6 +21,7 @@ */ #include "logging.hh" +#include 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); diff --git a/pdns/recursordist/logging.hh b/pdns/recursordist/logging.hh index 825ab36d03..246611023b 100644 --- a/pdns/recursordist/logging.hh +++ b/pdns/recursordist/logging.hh @@ -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 v(size_t level); diff --git a/pdns/recursordist/logr.hh b/pdns/recursordist/logr.hh index 2345c3f1fd..7a88fc06b3 100644 --- a/pdns/recursordist/logr.hh +++ b/pdns/recursordist/logr.hh @@ -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 diff --git a/pdns/rpzloader.cc b/pdns/rpzloader.cc index 3c27c1cd96..b387cd5674 100644 --- a/pdns/rpzloader.cc +++ b/pdns/rpzloader.cc @@ -313,7 +313,7 @@ static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptrerror(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_ptrerror(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_ptrerror(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; } -- 2.47.2