]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/config: fix get_val for booleans
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 23 Aug 2011 21:25:25 +0000 (14:25 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 23 Aug 2011 21:26:49 +0000 (14:26 -0700)
md_config_t::get_val should return true/false for booleans, not 0/1.
This is for consistency with the setter.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/config.cc
src/test/daemon_config.cc

index afc859a76d482f3b35df51af042cf80b4855e560..2706c10a43d9610221d8b78ab6499142a70c460f 100644 (file)
@@ -862,8 +862,10 @@ get_val(const char *key, char **buf, int len) const
       case OPT_DOUBLE:
         oss << *(double*)opt->conf_ptr(this);
         break;
-      case OPT_BOOL:
-        oss << *(bool*)opt->conf_ptr(this);
+      case OPT_BOOL: {
+         bool b = *(bool*)opt->conf_ptr(this);
+         oss << (b ? "true" : "false");
+       }
         break;
       case OPT_U32:
         oss << *(uint32_t*)opt->conf_ptr(this);
index 938531ab7686a1b9ca5a80c4f963e0848e86a789..9609fd5d4ce96f6d7b2af0e918379e222e9dc103 100644 (file)
@@ -131,6 +131,38 @@ TEST(DaemonConfig, InjectArgsReject) {
   ASSERT_EQ(string(buf), string(buf2));
 }
 
+TEST(DaemonConfig, InjectArgsBooleans) {
+  int ret;
+  char buf[128];
+  char *tmp = buf;
+  char buf2[128];
+  char *tmp2 = buf2;
+
+  // Change log_to_syslog
+  std::ostringstream chat;
+  std::string injection("--log_to_syslog --debug 28");
+  ret = g_ceph_context->_conf->injectargs(injection, &chat);
+  ASSERT_EQ(ret, 0);
+
+  // log_to_syslog should be set...
+  memset(buf, 0, sizeof(buf));
+  ret = g_ceph_context->_conf->get_val("log_to_syslog", &tmp, sizeof(buf));
+  ASSERT_EQ(ret, 0);
+  ASSERT_EQ(string("true"), string(buf));
+
+  // Turn off log_to_syslog
+  std::ostringstream chat2;
+  injection = "--log_to_syslog=false --debug 28";
+  ret = g_ceph_context->_conf->injectargs(injection, &chat2);
+  ASSERT_EQ(ret, 0);
+
+  // log_to_syslog should be cleared...
+  memset(buf, 0, sizeof(buf));
+  ret = g_ceph_context->_conf->get_val("log_to_syslog", &tmp, sizeof(buf));
+  ASSERT_EQ(ret, 0);
+  ASSERT_EQ(string("false"), string(buf));
+}
+
 TEST(DaemonConfig, InjectArgsLogfile) {
   int ret;
   std::ostringstream chat;