From: Miod Vallat Date: Mon, 16 Jun 2025 13:27:14 +0000 (+0200) Subject: Provide a more accurate error when stat() fails. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=56d3660faa8d54046f6e9de6ea1ecf42bc7dfb5f;p=thirdparty%2Fpdns.git Provide a more accurate error when stat() fails. Fixes: #9090 Signed-off-by: Miod Vallat --- diff --git a/pdns/misc.cc b/pdns/misc.cc index 23c3024071..0dcde9ffd7 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1807,10 +1807,17 @@ std::vector list_directory(const std::string& directory, const std: 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"; + if (stat(fullName.c_str(), &statInfo) != 0) { + int err = errno; + string msg = "Unable to stat file '" + fullName + "': " + stringerror(err); SLOG(g_log << Logger::Error << msg << std::endl, - d_log->info(Logr::Error, "Unable to open non-regular file", "name", Logging::Loggable(fullName))); + d_log->error(Logr::Error, err, "Unable to stat file", "name", Logging::Loggable(fullName))); + throw PDNSException(std::move(msg)); + } + if (!S_ISREG(statInfo.st_mode)) { + string msg = "File '" + fullName + "' is not a regular file"; + SLOG(g_log << Logger::Error << msg << std::endl, + d_log->info(Logr::Error, "File is not a regular file", "name", Logging::Loggable(fullName))); throw PDNSException(std::move(msg)); } results.emplace_back(fullName);