ctdb-common: Process the whole config file even if an error occurs
authorMartin Schwenke <martin@meltin.net>
Thu, 30 Aug 2018 23:35:14 +0000 (09:35 +1000)
committerKarolin Seeger <kseeger@samba.org>
Tue, 4 Sep 2018 10:14:30 +0000 (12:14 +0200)
At the moment multiple errors will be encountered one at a time, on
each load or validate.  Instead, allow all configuration errors to
printed in a single pass.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13589

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit 4f1727fe0bf2b0962a5d131d60a416b8f459ad94)

ctdb/common/conf.c
ctdb/tests/cunit/conf_test_001.sh
ctdb/tests/cunit/config_test_005.sh

index 8bc375b166d40fa11ad74f80729b7e7b2a9f463e..3d668de3122ac4b71bcc70a2add5e8136e711dfa 100644 (file)
@@ -1048,6 +1048,10 @@ static int conf_load_internal(struct conf_context *conf)
                }
        }
 
+       if (state.err != 0) {
+               goto fail;
+       }
+
        conf_all_update(conf);
        return 0;
 
@@ -1066,7 +1070,7 @@ static bool conf_load_section(const char *section, void *private_data)
                ok = conf_section_validate(state->conf, state->s, state->mode);
                if (!ok) {
                        state->err = EINVAL;
-                       return false;
+                       return true;
                }
        }
 
@@ -1078,7 +1082,7 @@ static bool conf_load_section(const char *section, void *private_data)
                } else {
                        D_ERR("conf: unknown section [%s]\n", section);
                        state->err = EINVAL;
-                       return false;
+                       return true;
                }
        }
 
@@ -1106,7 +1110,7 @@ static bool conf_load_option(const char *name,
                        D_ERR("conf: unknown section for option \"%s\"\n",
                              name);
                        state->err = EINVAL;
-                       return false;
+                       return true;
                }
        }
 
@@ -1122,7 +1126,7 @@ static bool conf_load_option(const char *name,
                              state->s->name,
                              name);
                        state->err = EINVAL;
-                       return false;
+                       return true;
                }
        }
 
@@ -1141,7 +1145,7 @@ static bool conf_load_option(const char *name,
                      value_str);
                talloc_free(tmp_ctx);
                state->err = ret;
-               return false;
+               return true;
        }
 
        ok = conf_option_same_value(opt, &value);
@@ -1153,7 +1157,7 @@ static bool conf_load_option(const char *name,
        if (ret != 0) {
                talloc_free(tmp_ctx);
                state->err = ret;
-               return false;
+               return true;
        }
 
 done:
index caca9314953ec72bfc2372b1ca80c42b1fde3748..d2ffa9887455872e59e18f42d0a815604aec2d3f 100755 (executable)
@@ -106,6 +106,7 @@ EOF
 
 required_result 22 <<EOF
 conf: unknown section [section2]
+conf: unknown section for option "foo"
 [section1]
        # key1 = value1
        # key2 = 10
index df636766b404037a83a31515f37258e853c60135..cd48a84a78ac96635bd290b93561d9c311ef52eb 100755 (executable)
@@ -30,6 +30,10 @@ EOF
 required_result 22 <<EOF
 volatile database directory "${dbdir_volatile}" does not exist
 conf: validation for option "volatile database directory" failed
+persistent database directory "${dbdir_persistent}" does not exist
+conf: validation for option "persistent database directory" failed
+state database directory "${dbdir_state}" does not exist
+conf: validation for option "state database directory" failed
 Failed to load config file $conffile
 EOF
 unit_test ctdb-config validate
@@ -39,6 +43,8 @@ mkdir -p "$dbdir_volatile"
 required_result 22 <<EOF
 persistent database directory "${dbdir_persistent}" does not exist
 conf: validation for option "persistent database directory" failed
+state database directory "${dbdir_state}" does not exist
+conf: validation for option "state database directory" failed
 Failed to load config file $conffile
 EOF
 unit_test ctdb-config validate