]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: clean up g_conf.id initialization a bit
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 1 Feb 2011 16:06:12 +0000 (08:06 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 1 Feb 2011 16:06:12 +0000 (08:06 -0800)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/config.cc
src/config.h

index f52c0ae1d693d8e2a31dcee2604bc5cc5222a571..3b3cc2c39b1c2bfed6598535e098f630fa02a359 100644 (file)
@@ -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<entity_name_t,float> g_fake_kill_after;
 
-
 md_config_t g_conf;
-bool g_daemon = false;
-
 
 #include <stdlib.h>
 #include <string.h>
@@ -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<const char*>& args, const char *mo
   std::vector<const char *> 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<const char*>& 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<const char*>& 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);
index b3f428f944a8ea373130874a424c2cfae0f7a58c..243e792a40ca542e180da91a3c620ec01dd438c6 100644 (file)
@@ -35,9 +35,6 @@ extern struct ceph_file_layout g_default_file_layout;
 #include <google/heap-profiler.h>
 #endif //HAVE_LIBTCMALLOC
 
-extern bool g_daemon;
-extern const char *g_default_id;
-
 struct EntityName;
 
 enum log_to_stderr_t {