ctdb-common: Avoid ENOENT for unknown conf options
authorMartin Schwenke <martin@meltin.net>
Thu, 30 Aug 2018 22:42:04 +0000 (08:42 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 3 Sep 2018 08:52:11 +0000 (10:52 +0200)
Only use ENOENT for missing configuration file.

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>
ctdb/common/conf.c
ctdb/tests/cunit/conf_test_001.sh
ctdb/tests/cunit/config_test_001.sh

index 2758d2628f25bf5192177ee3a5059c9e0b8ad9e3..8bc375b166d40fa11ad74f80729b7e7b2a9f463e 100644 (file)
@@ -1121,7 +1121,7 @@ static bool conf_load_option(const char *name,
                        D_ERR("conf: unknown option [%s] -> \"%s\"\n",
                              state->s->name,
                              name);
-                       state->err = ENOENT;
+                       state->err = EINVAL;
                        return false;
                }
        }
@@ -1207,16 +1207,16 @@ static int conf_set(struct conf_context *conf,
 
        s = conf_section_find(conf, section);
        if (s == NULL) {
-               return ENOENT;
+               return EINVAL;
        }
 
        opt = conf_option_find(s, key);
        if (opt == NULL) {
-               return ENOENT;
+               return EINVAL;
        }
 
        if (opt->type != value->type) {
-               return ENOENT;
+               return EINVAL;
        }
 
        ok = conf_option_same_value(opt, value);
@@ -1291,12 +1291,12 @@ static int conf_get(struct conf_context *conf,
 
        s = conf_section_find(conf, section);
        if (s == NULL) {
-               return ENOENT;
+               return EINVAL;
        }
 
        opt = conf_option_find(s, key);
        if (opt == NULL) {
-               return ENOENT;
+               return EINVAL;
        }
 
        if (opt->type != type) {
index a1a84585b1e87e451a10adde8c5dd850b1c54dcb..caca9314953ec72bfc2372b1ca80c42b1fde3748 100755 (executable)
@@ -120,7 +120,7 @@ cat > "$conffile" <<EOF
     key2 = 20
 EOF
 
-required_result 2 <<EOF
+required_error EINVAL <<EOF
 conf: unknown option [section1] -> "foo"
 [section1]
        # key1 = value1
index e58f710ac4d5ac20a8f0ba1beb0119b1a0e31992..d213aa88bfdb7a07170ea6544f56ac1e54f9abb3 100755 (executable)
@@ -101,7 +101,7 @@ cat > "$conffile" <<EOF
        log level = debug
 EOF
 
-required_result 2 <<EOF
+required_error EINVAL <<EOF
 conf: unknown option [database] -> "unknown key"
 Failed to load config file $conffile
 EOF