From: Colin Patrick McCabe Date: Tue, 1 Feb 2011 16:06:12 +0000 (-0800) Subject: common: clean up g_conf.id initialization a bit X-Git-Tag: v0.25~231^2~34 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=68f929a6c462d393516e43dd83c386538bf5b313;p=ceph.git common: clean up g_conf.id initialization a bit Signed-off-by: Colin McCabe --- diff --git a/src/config.cc b/src/config.cc index f52c0ae1d693..3b3cc2c39b1c 100644 --- a/src/config.cc +++ b/src/config.cc @@ -49,8 +49,6 @@ static ExportControl *ec = NULL; static void fini_g_conf(); -const char *g_default_id = "admin"; - static void env_override(char **ceph_var, const char * const env_var) { char *e = getenv(env_var); @@ -95,10 +93,7 @@ struct ceph_file_layout g_default_file_layout = { // fake osd failures: osd -> time std::map g_fake_kill_after; - md_config_t g_conf; -bool g_daemon = false; - #include #include @@ -755,6 +750,8 @@ static bool init_g_conf() set_conf_name(opt); } + g_conf.id = strdup("default"); + return true; } @@ -1093,8 +1090,6 @@ void parse_startup_config_options(std::vector& args, const char *mo std::vector nargs; bool conf_specified = false; - if (!g_conf.id) - g_conf.id = (char *)g_default_id; if (!g_conf.type) g_conf.type = (char *)""; @@ -1121,8 +1116,10 @@ void parse_startup_config_options(std::vector& args, const char *mo g_conf.daemonize = false; force_foreground_logging = true; } else if (isdaemon && (CONF_ARG_EQ("id", 'i') || CONF_ARG_EQ("name", 'n'))) { + free(g_conf.id); CONF_SAFE_SET_ARG_VAL(&g_conf.id, OPT_STR); } else if (!isdaemon && (CONF_ARG_EQ("id", 'I') || CONF_ARG_EQ("name", 'n'))) { + free(g_conf.id); CONF_SAFE_SET_ARG_VAL(&g_conf.id, OPT_STR); } else { nargs.push_back(args[i]); @@ -1133,25 +1130,23 @@ void parse_startup_config_options(std::vector& args, const char *mo if (module_type) { g_conf.type = strdup(module_type); - if (g_conf.id) { - // is it "type.name"? - const char *dot = strchr(g_conf.id, '.'); - if (dot) { - int tlen = dot - g_conf.id; - g_conf.type = (char *)malloc(tlen + 1); - memcpy(g_conf.type, g_conf.id, tlen); - g_conf.type[tlen] = 0; - g_conf.id = strdup(dot + 1); - } - - int len = strlen(g_conf.type) + strlen(g_conf.id) + 2; - g_conf.name = (char *)malloc(len); - snprintf(g_conf.name, len, "%s.%s", g_conf.type, g_conf.id); - g_conf.alt_name = (char *)malloc(len - 1); - snprintf(g_conf.alt_name, len - 1, "%s%s", module_type, g_conf.id); - } else { - g_conf.name = g_conf.type; + // is it "type.name"? + const char *dot = strchr(g_conf.id, '.'); + if (dot) { + int tlen = dot - g_conf.id; + g_conf.type = (char *)malloc(tlen + 1); + memcpy(g_conf.type, g_conf.id, tlen); + g_conf.type[tlen] = 0; + char *new_g_conf_id = strdup(dot + 1); + free(g_conf.id); + g_conf.id = new_g_conf_id; } + + int len = strlen(g_conf.type) + strlen(g_conf.id) + 2; + g_conf.name = (char *)malloc(len); + snprintf(g_conf.name, len, "%s.%s", g_conf.type, g_conf.id); + g_conf.alt_name = (char *)malloc(len - 1); + snprintf(g_conf.alt_name, len - 1, "%s%s", module_type, g_conf.id); } g_conf.entity_name = new EntityName; assert(g_conf.entity_name); diff --git a/src/config.h b/src/config.h index b3f428f944a8..243e792a40ca 100644 --- a/src/config.h +++ b/src/config.h @@ -35,9 +35,6 @@ extern struct ceph_file_layout g_default_file_layout; #include #endif //HAVE_LIBTCMALLOC -extern bool g_daemon; -extern const char *g_default_id; - struct EntityName; enum log_to_stderr_t {