]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
conf: exit if -c specified and conf file not found
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 24 Mar 2009 19:47:11 +0000 (12:47 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 24 Mar 2009 19:47:31 +0000 (12:47 -0700)
src/common/ConfUtils.cc
src/common/ConfUtils.h
src/config.cc

index 132d2ad1c48e1648d34bce27ae657918ead72ffa..94ce38b481b71b73251ebb51cfb0f4132dd95cca 100644 (file)
@@ -526,7 +526,7 @@ ConfSection *ConfFile::_add_section(const char *section, ConfLine *cl)
 }
 
 
-int ConfFile::_parse(char *filename, ConfSection **psection)
+bool ConfFile::_parse(char *filename, ConfSection **psection)
 {
        char *buf;
        int len, i, l;
@@ -593,7 +593,7 @@ int ConfFile::_parse(char *filename, ConfSection **psection)
        return 1;
 }
 
-int ConfFile::parse()
+bool ConfFile::parse()
 {
        ConfSection *section;
 
index 3ad7b3c9b2b42af3932b914f439b7e9dca661a72..c1e7b88a3673be99d419bc844ebbdcceca562977 100644 (file)
@@ -83,7 +83,7 @@ class ConfFile {
 
        ConfSection *_add_section(const char *section, ConfLine *cl);
        void _dump(int fd);
-       int _parse(char *filename, ConfSection **psection);
+       bool _parse(char *filename, ConfSection **psection);
 public:
         ConfFile(const char *fname) : filename(strdup(fname)), auto_update(false),
                                      post_process_func(NULL) {}
@@ -92,7 +92,7 @@ public:
        const SectionList& get_section_list() { return sections_list; }
        const char *get_filename() { return filename; }
 
-       int parse();
+       bool parse();
        int read(const char *section, const char *var, int *val, int def_val);
        int read(const char *section, const char *var, unsigned int *val, unsigned int def_val);
        int read(const char *section, const char *var, long long *val, long long def_val);
index 9d53eeb91513eb5a8842e6baa559c727a82cc2e1..51ee6dd46fc4245513efc763b56c8b7e9ee2530f 100644 (file)
@@ -916,18 +916,21 @@ int conf_read_key(const char *alt_section, const char *key, opt_type_t type, voi
   return ret;
 }
 
-void parse_config_file(ConfFile *cf, bool auto_update)
+bool parse_config_file(ConfFile *cf, bool auto_update)
 {
   int opt_len = sizeof(config_optionsp)/sizeof(config_option);
 
   cf->set_auto_update(false);
   cf->set_post_process_func(conf_post_process_val);
-  cf->parse();
+  if (!cf->parse())
+       return false;
 
   for (int i=0; i<opt_len; i++) {
       config_option *opt = &config_optionsp[i];
       conf_read_key(NULL, opt->conf_name, opt->type, opt->val_ptr, opt->val_ptr);
   }
+
+  return true;
 }
 
 bool is_bool_param(const char *param)
@@ -939,6 +942,7 @@ void parse_startup_config_options(std::vector<const char*>& args, const char *mo
 {
   DEFINE_CONF_VARS(NULL);
   std::vector<const char *> nargs;
+  bool conf_specified = false;
 
   if (!g_conf.id)
     g_conf.id = (char *)"";
@@ -948,6 +952,7 @@ void parse_startup_config_options(std::vector<const char*>& args, const char *mo
   FOR_EACH_ARG(args) {
     if (CONF_ARG_EQ("conf", 'c')) {
        CONF_SAFE_SET_ARG_VAL(&g_conf.conf, OPT_STR);
+       conf_specified = true;
     } else if (CONF_ARG_EQ("monmap", 'M')) {
        CONF_SAFE_SET_ARG_VAL(&g_conf.monmap, OPT_STR);
     } else if (CONF_ARG_EQ("bind", 0)) {
@@ -990,7 +995,12 @@ void parse_startup_config_options(std::vector<const char*>& args, const char *mo
 
   cf = new ConfFile(g_conf.conf);
 
-  parse_config_file(cf, true);
+  int ret = parse_config_file(cf, true);
+
+  if (conf_specified && !ret) {
+    cerr << "error reading config file " << g_conf.conf << std::endl;
+    exit(1);
+  }
 
   if (show_config) {
     cf->dump();