common/config: fix get_val for booleans

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>
This commit is contained in:
Colin Patrick McCabe 2011-08-23 14:25:25 -07:00
parent 9c498e0f1e
commit 3432729397
2 changed files with 36 additions and 2 deletions

View 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);

View 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;