]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
confutils: some more changes
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 21 Jan 2009 21:54:51 +0000 (13:54 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 23 Jan 2009 17:31:42 +0000 (09:31 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
src/common/ConfUtils.cc
src/config.cc

index 16e9a83bf72c8a43c0d75ac16bed4ebd22c03467..11bf08b1ede80e553fe9cf85b4029d7716280d81 100644 (file)
@@ -214,6 +214,7 @@ static int _str_cat(char *str1, int max, char *str2)
 
 void ConfFile::dump()
 {
+#if 0
        std::list<struct conf_line *>::iterator iter, end;
        struct conf_line *cl;
        char line[MAX_LINE];
@@ -243,6 +244,22 @@ void ConfFile::dump()
                        printf("line=%s\n", line);
                }
        }
+#endif
+       ConfMap *cur_map;
+       ConfMap::iterator map_iter, map_end;
+       SectionMap::iterator sec_iter, sec_end;
+
+       sec_end = sections.end();
+
+       for (sec_iter = sections.begin(); sec_iter != sec_end; ++sec_iter) {
+               cur_map = sec_iter->second;
+               map_end = cur_map->end();
+
+               for (map_iter = cur_map->begin(); map_iter != map_end; ++map_iter) {
+                       
+               }
+       }
+
 }
 
 int ConfFile::parse()
@@ -406,6 +423,22 @@ notfound:
        return 0;
 }
 
+int ConfFile::read_str_alloc(char *section, char *var, char **val, char *def_val)
+{
+       struct conf_line *cl;
+
+       cl = _find_var(section, var);
+       if (!cl || !cl->val)
+               goto notfound;
+
+       *val = strdup(cl->val);
+
+       return 1;
+notfound:
+       *val = strdup(def_val);
+       return 0;
+}
+
 void parse_test(char *line)
 {
        struct conf_line cl;
index 4f6212d1d60faa628059e5b4a5c66d8553a2bb65..ae173710fb717661b1bb33eeddfdf36eee51b4af 100644 (file)
@@ -36,6 +36,8 @@ atomic_t buffer_total_alloc;
 
 #include "osd/osd_types.h"
 
+#include "common/ConfUtils.h"
+
 int buffer::list::read_file(const char *fn)
 {
   struct stat st;
@@ -604,7 +606,10 @@ void parse_config_file(char *fname)
   cf.parse();
 
 #define CF_READ(section, type, field, inout) \
-  cf.read_#type(section, ##field, &inout, inout)
+  cf.read_##type((char *)section, (char *)#field, &inout, inout)
+
+#define CF_READ_STR(section, type, field, inout) \
+  cf.read_##type((char *)section, (char *)#field, (char **)&inout, (char *)inout)
 
   CF_READ("global", int, num_mon, g_conf.num_mon);
   CF_READ("global", int, num_mon, g_conf.num_mds);
@@ -614,11 +619,11 @@ void parse_config_file(char *fname)
   CF_READ("global", bool, file_logs, g_conf.file_logs);
   CF_READ("global", bool, log, g_conf.log);
   CF_READ("global", int, log_interval, g_conf.log_interval);
-  CF_READ("global", str, log_name, g_conf.log_name);
+  CF_READ_STR("global", str_alloc, log_name, g_conf.log_name);
   CF_READ("global", bool, log_messages, g_conf.log_messages);
   CF_READ("global", bool, log_pins, g_conf.log_pins);
-  CF_READ("global", bool, dout_dir, g_conf.dout_dir);
-  CF_READ("global", bool, dout_sym_dir, g_conf.dout_sym_dir);
+  CF_READ_STR("global", str_alloc, dout_dir, g_conf.dout_dir);
+  CF_READ_STR("global", str_alloc, dout_sym_dir, g_conf.dout_sym_dir);
 }
 
 void parse_config_options(std::vector<const char*>& args, bool open)