]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
conf: can specify environment variables for substitution
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 15 Jun 2010 21:13:13 +0000 (14:13 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 16 Jun 2010 17:14:20 +0000 (10:14 -0700)
src/config.cc

index 085b100e512030897b8ac21492643d6350c93918..5aa62f89d19bdcf4a033391f24c4079f586f80a2 100644 (file)
@@ -748,7 +748,8 @@ static bool get_var(const char *str, int pos, char *var_name, int len, int *new_
 
   while (str[pos] &&
        ((bracket && str[pos] != '}') ||
-        isalnum(str[pos]))) {
+        isalnum(str[pos]) ||
+         str[pos] == '_')) {
        var_name[out_pos] = str[pos];
        
        out_pos ++;
@@ -759,6 +760,7 @@ static bool get_var(const char *str, int pos, char *var_name, int len, int *new_
 
   var_name[out_pos] = '\0';
 
+
   if (bracket && (str[pos] == '}'))
        pos++;
 
@@ -769,6 +771,8 @@ static bool get_var(const char *str, int pos, char *var_name, int len, int *new_
 
 static const char *var_val(char *var_name)
 {
+       const char *val;
+
        if (strcmp(var_name, "type")==0)
                return g_conf.type;
        if (strcmp(var_name, "id")==0)
@@ -778,9 +782,13 @@ static const char *var_val(char *var_name)
        if (strcmp(var_name, "name")==0)
                return g_conf.name;
        if (strcmp(var_name, "host")==0)
-         return g_conf.host;
+               return g_conf.host;
+
+       val = getenv(var_name);
+       if (!val)
+               val = "";
 
-       return "";
+       return val;
 }
 
 #define MAX_LINE 256