]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
conf: make dup lines override previous value
authorSage Weil <sage@inktank.com>
Fri, 20 Jul 2012 15:55:21 +0000 (08:55 -0700)
committerSage Weil <sage@inktank.com>
Fri, 27 Jul 2012 17:43:27 +0000 (10:43 -0700)
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 <sage@inktank.com>
src/common/ConfUtils.cc
src/test/confutils.cc

index e339205b5ea58b69dc3da6c52bb7bc184a8d26d7..b3f7f39258239296c63873b4a751c205bf8be3fd 100644 (file)
@@ -360,7 +360,18 @@ load_from_buffer(const char *buf, size_t sz, std::deque<std::string> *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);
index e024da3b4b9e3f3242a8178ec0267bc9f413f1ed..a504032630d81e42e2861b2c83c1b110376c6a1d 100644 (file)
@@ -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<std::string> 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"));
+}