]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
config: ConfFile::open: return error code
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 9 Mar 2011 12:55:51 +0000 (04:55 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 9 Mar 2011 13:05:33 +0000 (05:05 -0800)
Return a integer result code specifying why we failed, if we fail.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/auth/KeyRing.cc
src/cauthtool.cc
src/common/ConfUtils.cc
src/common/ConfUtils.h
src/common/config.cc
src/mon/MonClient.cc

index 1ea1d988fc2d54dff3f763839b8126d1ce76d2c0..d6e14695c904f14f6067938ac1303b94fe07a1c1 100644 (file)
@@ -108,7 +108,7 @@ void KeyRing::decode_plaintext(bufferlist::iterator& bli)
 
   cf.set_global(false);
 
-  if (!cf.parse()) {
+  if (cf.parse() != 0) {
     derr << "cannot parse buffer" << dendl;
     goto done_err;
   }
index 708930afadd99f006425d1111769afa09338be1b..21021fcab313fba7d1efb4288b797d19829e79b3 100644 (file)
@@ -208,7 +208,7 @@ int main(int argc, const char **argv)
   }
   if (caps_fn) {
     ConfFile *cf = new ConfFile(caps_fn);
-    if (!cf->parse()) {
+    if (cf->parse() != 0) {
       cerr << "could not parse caps file " << caps_fn << std::endl;
       exit(1);
     }
index 42a6db7af3d2e54ca10ee97b4beb75c9f0f67edf..a2b42b45d70629b34567419d7ad58b4042f5a71a 100644 (file)
@@ -623,19 +623,6 @@ ConfSection *ConfFile::_add_section(const char *section, ConfLine *cl)
        return sec;
 }
 
-int ConfFile::_open()
-{
-       if (filename)
-               return open(filename, O_RDONLY);
-
-       if (!pbl)
-               return -EINVAL;
-
-       buf_pos = 0;
-
-       return 0;
-}
-
 int ConfFile::_read(int fd, char *buf, size_t size)
 {
        if (filename)
@@ -665,7 +652,7 @@ int ConfFile::_close(int fd)
        return 0;
 }
 
-bool ConfFile::_parse(const char *filename, ConfSection **psection)
+int ConfFile::_parse(const char *filename, ConfSection **psection)
 {
        char *buf;
        int len, i, l;
@@ -675,11 +662,18 @@ bool ConfFile::_parse(const char *filename, ConfSection **psection)
        int fd;
        int max_line = MAX_LINE;
        int eof = 0;
-       bool ret = true;
+       bool ret = 0;
 
-       fd = _open();
-       if (fd < 0)
-               return false;
+       if (filename) {
+               fd = open(filename, O_RDONLY);
+               if (fd < 0)
+                       return -errno;
+       }
+       else {
+               if (!pbl)
+                       return -EINVAL;
+               buf_pos = 0;
+       }
 
        line = (char *)malloc(max_line);
        l = 0;
@@ -688,7 +682,7 @@ bool ConfFile::_parse(const char *filename, ConfSection **psection)
        do {
                len = _read(fd, buf, BUF_SIZE);
                if (len < 0) {
-                       ret = false;
+                       ret = -EDOM;
                        goto done;
                }
 
@@ -714,7 +708,7 @@ bool ConfFile::_parse(const char *filename, ConfSection **psection)
                                if (cl->get_var()) {
                                        if (strcmp(cl->get_var(), "include") == 0) {
                                                if (!filename) { // don't allow including if we're not using files
-                                                       ret = false;
+                                                       ret = -EDOM;
                                                        goto done;
                                                }
                                                if (!_parse(cl->get_val(), &section)) {
@@ -723,7 +717,7 @@ bool ConfFile::_parse(const char *filename, ConfSection **psection)
                                        } else {
                                                char *norm_var = cl->get_norm_var();
                                                if (!section) {
-                                                       ret = false;
+                                                       ret = -EDOM;
                                                        goto done;
                                                }
                                                section->conf_map[norm_var] = cl;
@@ -758,7 +752,7 @@ done:
        return ret;
 }
 
-bool ConfFile::parse()
+int ConfFile::parse()
 {
        ConfSection *section = NULL;
 
@@ -770,7 +764,7 @@ bool ConfFile::parse()
                sections_list.push_back(section);
        }
 
-       bool res = _parse(filename, &section);
+       int res = _parse(filename, &section);
        parse_lock.Unlock();
        return res;
 }
index c7a08682e01b4032765e17efc84686bd1b58e16b..58a6e49271d6ced5130e96e6b99c1443904676e9 100644 (file)
@@ -91,11 +91,10 @@ class ConfFile {
 
        ConfSection *_add_section(const char *section, ConfLine *cl);
        void _dump(int fd);
-       bool _parse(const char *filename, ConfSection **psection);
+       int _parse(const char *filename, ConfSection **psection);
        void common_init();
 
        int _read(int fd, char *buf, size_t size);
-       int _open();
        int _close(int fd);
 public:
         ConfFile(const char *fname);
@@ -105,7 +104,7 @@ public:
        const SectionList& get_section_list() { return sections_list; }
        const char *get_filename() { return filename; }
 
-       bool parse();
+       int 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 ce4223964fa3fee4004461f7f0e2f336b02f44ab..ef5c6ec69db2c288df1dbdd4051e377cb0032286 100644 (file)
@@ -833,7 +833,7 @@ bool parse_config_file(ConfFile *cf, bool auto_update)
   int opt_len = sizeof(config_optionsp)/sizeof(config_option);
 
   cf->set_post_process_func(conf_post_process_val);
-  if (!cf->parse())
+  if (cf->parse() != 0)
   return false;
 
   for (int i=0; i<opt_len; i++) {
index 6ec26108dc555a68680fa0abfff59b950a29991a..cf0462c6a29a954544aab74437421bfa3c313b9d 100644 (file)
@@ -110,7 +110,7 @@ int MonClient::build_initial_monmap()
   if (!ls.empty()) {
     for (list<string>::iterator p = ls.begin(); p != ls.end(); p++) {
       ConfFile c(p->c_str());
-      if (c.parse()) {
+      if (c.parse() == 0) {
        for (list<ConfSection*>::const_iterator q = c.get_section_list().begin();
             q != c.get_section_list().end();
             q++) {