BIND 10 trac2377, updated. cbffb4ac5bf27888553a102ac6ee2a1fbf07642b [2377] Handle errors on file open
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Dec 3 12:12:26 UTC 2012
The branch, trac2377 has been updated
via cbffb4ac5bf27888553a102ac6ee2a1fbf07642b (commit)
from b548f4ed6cc20a5d8bb802aed646af007c0653b8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit cbffb4ac5bf27888553a102ac6ee2a1fbf07642b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Dec 3 13:11:16 2012 +0100
[2377] Handle errors on file open
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_loader.cc | 28 +++++++++++++++++++--------
src/lib/dns/tests/master_loader_unittest.cc | 25 ++++++++++++++++++++----
2 files changed, 41 insertions(+), 12 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index 06cf7c5..1acb14b 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -38,12 +38,17 @@ public:
zone_class_(zone_class),
callbacks_(callbacks),
add_callback_(add_callback),
- options_(options)
- {
- string errors;
- if (!lexer_.pushSource(master_file, &errors)) {
- // TODO: Handle somehow.
- assert(0);
+ options_(options),
+ master_file_(master_file),
+ initialized_(false),
+ ok_(true)
+ {}
+
+ void pushSource(const std::string& filename) {
+ std::string error;
+ if (!lexer_.pushSource(filename.c_str(), &error)) {
+ ok_ = false;
+ callbacks_.error("", 0, error);
}
}
@@ -53,8 +58,11 @@ public:
}
bool loadIncremental(size_t count_limit) {
+ if (!initialized_) {
+ pushSource(master_file_);
+ }
size_t count = 0;
- while (count < count_limit) {
+ while (ok_ && count < count_limit) {
// Skip all EOLNs (empty lines) and finish on EOF
bool empty = true;
do {
@@ -93,7 +101,8 @@ public:
++count;
};
}
- return (false);
+ // When there was a fatal error and ok is false, we say we are done.
+ return (!ok_);
}
private:
@@ -103,6 +112,9 @@ private:
MasterLoaderCallbacks callbacks_;
AddRRCallback add_callback_;
MasterLoader::Options options_;
+ const std::string master_file_;
+ bool initialized_;
+ bool ok_;
};
MasterLoader::MasterLoader(const char* master_file,
diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc
index 7b27579..e7ebdee 100644
--- a/src/lib/dns/tests/master_loader_unittest.cc
+++ b/src/lib/dns/tests/master_loader_unittest.cc
@@ -47,7 +47,7 @@ public:
const std::string reason)
{
std::stringstream ss;
- ss << file << line << reason;
+ ss << reason << " [" << file << ":" << line << "]";
if (error) {
errors_.push_back(ss.str());
} else {
@@ -97,9 +97,7 @@ public:
// Test simple loading. The zone file contains no tricky things, and nothing is
// omitted. No RRset contains more than one RR Also no errors or warnings.
TEST_F(MasterLoaderTest, basicLoad) {
- setLoader("example.org",
- Name("example.org."),
- RRClass::IN(),
+ setLoader("example.org", Name("example.org."), RRClass::IN(),
MasterLoader::MANY_ERRORS);
loader_->load();
@@ -112,3 +110,22 @@ TEST_F(MasterLoaderTest, basicLoad) {
checkRR("example.org", RRType::NS(), "ns1.example.org.");
checkRR("www.example.org", RRType::A(), "192.0.2.1");
}
+
+// Try loading from file that doesn't exist. There should be single error
+// saying so.
+TEST_F(MasterLoaderTest, invalidFile) {
+ setLoader("This file doesn't exist at all",
+ Name("exmaple.org."), RRClass::IN(), MasterLoader::MANY_ERRORS);
+
+ // Nothing yet. The loader is dormant until invoked.
+ // Is it really what we want?
+ EXPECT_TRUE(errors_.empty());
+
+ loader_->load();
+
+ EXPECT_TRUE(warnings_.empty());
+ EXPECT_TRUE(rrsets_.empty());
+ ASSERT_EQ(1, errors_.size());
+ EXPECT_EQ(0, errors_[0].find("Error opening the input source file: ")) <<
+ "Different error: " << errors_[0];
+}
More information about the bind10-changes
mailing list