From: Sage Weil Date: Fri, 20 Jul 2012 15:55:21 +0000 (-0700) Subject: conf: make dup lines override previous value X-Git-Tag: v0.51~59^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f69d025b3ce9a68e67e329ae9c355fb2c2fde927;p=ceph.git conf: make dup lines override previous value If you put [some section] foo = 1 ... foo = 2 in a .conf file, make the second key override the first. Generate a warning if a value is overridden to sidestep some user hangbanging. Signed-off-by: Sage Weil --- diff --git a/src/common/ConfUtils.cc b/src/common/ConfUtils.cc index e339205b5ea5..b3f7f3925823 100644 --- a/src/common/ConfUtils.cc +++ b/src/common/ConfUtils.cc @@ -360,7 +360,18 @@ load_from_buffer(const char *buf, size_t sz, std::deque *errors) pair < section_iter_t, bool > nr(sections.insert(nt)); cur_section = nr.first; } - else if (!cline->key.empty()) { + else { + if (cur_section->second.lines.count(*cline)) { + // replace an existing key/line in this section, so that + // [mysection] + // foo = 1 + // foo = 2 + // will result in foo = 2. + cur_section->second.lines.erase(*cline); + if (cline->key.length()) + std::cerr << "warning: line " << line_no << ": '" << cline->key << "' in section '" + << cur_section->first << "' redefined " << std::endl; + } // add line to current section //std::cerr << "cur_section = " << cur_section->first << ", " << *cline << std::endl; cur_section->second.lines.insert(*cline); diff --git a/src/test/confutils.cc b/src/test/confutils.cc index e024da3b4b9e..a504032630d8 100644 --- a/src/test/confutils.cc +++ b/src/test/confutils.cc @@ -257,6 +257,12 @@ const char override_config_1[] = "\ log file = osd0_log\n\ "; +const char dup_key_config_1[] = "\ +[mds.a]\n\ + log_file = 1\n\ + log_file = 3\n\ +"; + TEST(Whitespace, ConfUtils) { std::string test0(""); ConfFile::trim_whitespace(test0, false); @@ -478,3 +484,14 @@ TEST(Overrides, ConfUtils) { ASSERT_EQ(err.size(), 0U); ASSERT_EQ(conf.log_file, "osd0_log"); } + +TEST(DupKey, ConfUtils) { + md_config_t conf; + std::deque err; + std::string dup_key_config_f(next_tempfile(dup_key_config_1)); + + conf.name.set(CEPH_ENTITY_TYPE_MDS, "a"); + conf.parse_config_files(dup_key_config_f.c_str(), &err, 0); + ASSERT_EQ(err.size(), 0U); + ASSERT_EQ(conf.log_file, string("3")); +}