dnsname.cc dnsname.hh \
ednsoptions.cc ednsoptions.hh \
fuzz_packetcache.cc \
+ logger.cc logger.hh \
+ logging.cc logging.hh \
misc.cc misc.hh \
packetcache.hh \
qtype.cc qtype.hh \
return; // nothing to do
}
- std::vector<std::string> vec;
- auto directoryError = pdns::visit_directory(directory, [this, &directory, &suffix, &vec]([[maybe_unused]] ino_t inodeNumber, const std::string_view& name) {
- (void)this;
- if (boost::starts_with(name, ".")) {
- return true; // skip any dots
- }
- if (boost::ends_with(name, suffix)) {
- // build name
- string fullName = directory + "/" + std::string(name);
- // ensure it's readable file
- struct stat statInfo{};
- if (stat(fullName.c_str(), &statInfo) != 0 || !S_ISREG(statInfo.st_mode)) {
- string msg = fullName + " is not a regular file";
- SLOG(g_log << Logger::Error << msg << std::endl,
- d_log->info(Logr::Error, "Unable to open non-regular file", "name", Logging::Loggable(fullName)));
- throw ArgException(std::move(msg));
- }
- vec.emplace_back(fullName);
- }
- return true;
- });
-
- if (directoryError) {
- int err = errno;
- string msg = directory + " is not accessible: " + stringerror(err);
- SLOG(g_log << Logger::Error << msg << std::endl,
- d_log->error(Logr::Error, err, "Directory is not accessible", "name", Logging::Loggable(directory)));
- throw ArgException(std::move(msg));
- }
-
+ std::vector<std::string> vec = pdns::list_directory(directory, suffix, d_log);
std::sort(vec.begin(), vec.end(), CIStringComparePOSIX());
extraConfigs.insert(extraConfigs.end(), vec.begin(), vec.end());
}
#include "namespaces.hh"
+bool g_slogStructured{false};
+
StatBag S;
struct Entry
--- /dev/null
+../logger.hh
\ No newline at end of file
What it does is provide answers to queries from the Lua generic UDP Question/Answer
stuff in kv-example-script.lua */
+bool g_slogStructured{false};
+
StatBag S;
int main(int argc, char** argv)
};
void BaseLua4::includePath(const std::string& directory) {
- std::vector<std::string> vec;
const std::string& suffix = "lua";
- auto directoryError = pdns::visit_directory(directory, [this, &directory, &suffix, &vec]([[maybe_unused]] ino_t inodeNumber, const std::string_view& name) {
- (void)this;
- if (boost::starts_with(name, ".")) {
- return true; // skip any dots
- }
- if (boost::ends_with(name, suffix)) {
- // build name
- string fullName = directory + "/" + std::string(name);
- // ensure it's readable file
- struct stat statInfo
- {
- };
- if (stat(fullName.c_str(), &statInfo) != 0 || !S_ISREG(statInfo.st_mode)) {
- string msg = fullName + " is not a regular file";
- SLOG(g_log << Logger::Error << msg << std::endl,
- g_slog->withName("lua")->info(Logr::Error, "include file is not a regular file", "file", Logging::Loggable(fullName)));
- throw PDNSException(std::move(msg));
- }
- vec.emplace_back(fullName);
- }
- return true;
- });
-
- if (directoryError) {
- int err = errno;
- string msg = directory + " is not accessible: " + stringerror(err);
- SLOG(g_log << Logger::Error << msg << std::endl,
- g_slog->withName("lua")->error(Logr::Error, err, "Error trying to walk directory", "directory", Logging::Loggable(directory)));
- throw PDNSException(std::move(msg));
- }
-
+ std::vector<std::string> vec = pdns::list_directory(directory, suffix, g_slog->withName("lua"));
std::sort(vec.begin(), vec.end(), CIStringComparePOSIX());
-
for(const auto& file: vec) {
loadFile(file, false);
}
#include <sys/param.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/time.h>
#include "iputils.hh"
#include "dnsparser.hh"
#include "dns_random.hh"
+#include "logger.hh"
+#include "logging.hh"
#include <pwd.h>
#include <grp.h>
#include <climits>
return std::nullopt;
}
+std::vector<std::string> list_directory(const std::string& directory, const std::string& suffix, Logr::log_t d_log)
+{
+ std::vector<std::string> results;
+
+ auto directoryError = pdns::visit_directory(directory,
+ [&directory, &suffix, &results, d_log]
+ ([[maybe_unused]] ino_t inodeNumber, const std::string_view& name) {
+ if (boost::starts_with(name, ".")) {
+ return true; // skip any dots
+ }
+ if (boost::ends_with(name, suffix)) {
+ // build name
+ string fullName = directory + "/" + std::string(name);
+ // ensure it's a readable file
+ struct stat statInfo{};
+ if (stat(fullName.c_str(), &statInfo) != 0 || !S_ISREG(statInfo.st_mode)) {
+ string msg = fullName + " is not a regular file";
+ SLOG(g_log << Logger::Error << msg << std::endl,
+ d_log->info(Logr::Error, "Unable to open non-regular file", "name", Logging::Loggable(fullName)));
+ throw PDNSException(std::move(msg));
+ }
+ results.emplace_back(fullName);
+ }
+ return true;
+ });
+
+ if (directoryError) {
+ int err = errno;
+ string msg = directory + " is not accessible: " + stringerror(err);
+ SLOG(g_log << Logger::Error << msg << std::endl,
+ d_log->error(Logr::Error, err, "Directory is not accessible", "name", Logging::Loggable(directory)));
+ throw PDNSException(std::move(msg));
+ }
+
+ return results;
+}
+
UniqueFilePtr openFileForWriting(const std::string& filePath, mode_t permissions, bool mustNotExist, bool appendIfExists)
{
int flags = O_WRONLY | O_CREAT;
#include <vector>
#include "namespaces.hh"
+#include "logr.hh"
class DNSName;
#if defined(PDNS_AUTH)
{
[[nodiscard]] std::optional<std::string> visit_directory(const std::string& directory, const std::function<bool(ino_t inodeNumber, const std::string_view& name)>& visitor);
+std::vector<std::string> list_directory(const std::string& directory, const std::string& suffix, Logr::log_t d_log);
+
struct FilePtrDeleter
{
/* using a deleter instead of decltype(&fclose) has two big advantages: