From: Yehuda Sadeh Date: Thu, 12 Mar 2009 21:03:04 +0000 (-0700) Subject: cconf: fix -s options and some other cleanup X-Git-Tag: v0.7.1^2~67 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c446d4344c91ba00e5e664bb65fd7117d4492f5c;p=ceph.git cconf: fix -s options and some other cleanup --- diff --git a/src/cconf.cc b/src/cconf.cc index ac91fced728b..82beeb0aa3ff 100644 --- a/src/cconf.cc +++ b/src/cconf.cc @@ -60,8 +60,6 @@ int main(int argc, const char **argv) else usage(); } else if (strcmp(args[i], "-s") == 0) { - if (param == 0) - param++; if (i < args.size() - 1) sections.push_back(args[++i]); else @@ -79,7 +77,7 @@ int main(int argc, const char **argv) } } - if (!list_sections && (param < 1 || param > 3)) + if (!list_sections && (param < 1 || param > 2)) usage(); ConfFile *cf = conf_get_conf_file(); diff --git a/src/config.cc b/src/config.cc index feeb978931fe..634336068683 100644 --- a/src/config.cc +++ b/src/config.cc @@ -586,7 +586,7 @@ static struct config_option config_optionsp[] = { OPTION(bdev_fake_max_mb, 0, OPT_INT, 0), }; -static bool set_conf_val(void *field, opt_type_t type, const char *val) +bool conf_set_conf_val(void *field, opt_type_t type, const char *val) { switch (type) { case OPT_BOOL: @@ -665,7 +665,7 @@ static bool init_g_conf() for (i = 0; ival_ptr, + if (!conf_set_conf_val(opt->val_ptr, opt->type, opt->def_val)) { cerr << "error initializing g_conf value num " << i << std::endl; @@ -686,7 +686,7 @@ static bool cmd_is_char(const char *cmd) cmd[1] && !cmd[2]); } -static bool cmd_equals(const char *cmd, const char *opt, char char_opt, unsigned int *val_pos) +static bool conf_cmd_equals(const char *cmd, const char *opt, char char_opt, unsigned int *val_pos) { unsigned int i; unsigned int len = strlen(opt); @@ -881,53 +881,59 @@ void parse_config_file(ConfFile *cf, bool auto_update) } +#define CONF_NEXT_VAL (val_pos ? &args[i][val_pos] : args[++i]) +#define CONF_SET_ARG_VAL(dest, type) \ + conf_set_conf_val(dest, type, CONF_NEXT_VAL) +#define CONF_SAFE_SET_ARG_VAL(dest, type) \ + do { \ + if (__isarg || val_pos) \ + CONF_SET_ARG_VAL(dest, type); \ + } while (0) +#define CONF_SET_BOOL_ARG_VAL(dest) \ + conf_set_conf_val(dest, OPT_BOOL, (val_pos ? &args[i][val_pos] : "true")) +#define CONF_ARG_EQ(str_cmd, char_cmd) \ + conf_cmd_equals(args[i], str_cmd, char_cmd, &val_pos) + +#define DEFINE_CONF_VARS \ +unsigned int val_pos; \ +bool __isarg + +#define FOR_EACH_ARG(args) \ +__isarg = 1 < args.size(); \ +for (unsigned i=0; i& args, const char *module_type) { - unsigned int val_pos; + DEFINE_CONF_VARS; + std::vector nargs; - std::vector nargs; - if (!g_conf.id) g_conf.id = (char *)""; if (!g_conf.type) g_conf.type = (char *)""; - for (unsigned i=0; i& args) { int opt_len = sizeof(config_optionsp)/sizeof(config_option); - unsigned int val_pos; + DEFINE_CONF_VARS; std::vector nargs; - for (unsigned i=0; i