diff --git a/conf.h b/conf.h index eee209ff..7f81ae10 100644 --- a/conf.h +++ b/conf.h @@ -314,7 +314,7 @@ void _cf_warn_node_value(struct __sourceloc __whence, const struct cf_om_node *n void _cf_warn_no_array(struct __sourceloc __whence, const struct cf_om_node *node, int reason); void _cf_warn_unsupported_node(struct __sourceloc __whence, const struct cf_om_node *node); void _cf_warn_unsupported_children(struct __sourceloc __whence, const struct cf_om_node *parent); -void _cf_warn_list_overflow(struct __sourceloc __whence, const struct cf_om_node *node); +void _cf_warn_list_overflow(struct __sourceloc __whence, const struct cf_om_node *node, const char *fmt, ...); void _cf_warn_incompatible(struct __sourceloc __whence, const struct cf_om_node *node, const struct cf_om_node *orig); void _cf_warn_incompatible_children(struct __sourceloc __whence, const struct cf_om_node *parent); void _cf_warn_array_key(struct __sourceloc __whence, const struct cf_om_node *node, int reason); @@ -330,7 +330,7 @@ void _cf_warn_array_value(struct __sourceloc __whence, const struct cf_om_node * #define cf_warn_no_array(node, reason) _cf_warn_no_array(__WHENCE__, node, reason) #define cf_warn_unsupported_node(node) _cf_warn_unsupported_node(__WHENCE__, node) #define cf_warn_unsupported_children(parent) _cf_warn_unsupported_children(__WHENCE__, parent) -#define cf_warn_list_overflow(node) _cf_warn_list_overflow(__WHENCE__, node) +#define cf_warn_list_overflow(node, fmt, ...) _cf_warn_list_overflow(__WHENCE__, node, fmt, ##__VA_ARGS__) #define cf_warn_incompatible(node, orig) _cf_warn_incompatible(__WHENCE__, node, orig) #define cf_warn_incompatible_children(parent) _cf_warn_incompatible_children(__WHENCE__, parent) #define cf_warn_array_key(node, reason) _cf_warn_array_key(__WHENCE__, node, reason) diff --git a/conf_om.c b/conf_om.c index b8e6d8ef..de3c49b6 100644 --- a/conf_om.c +++ b/conf_om.c @@ -493,7 +493,10 @@ void _cf_warn_childrenv(struct __sourceloc __whence, const struct cf_om_node *pa { unsigned i; for (i = 0; i < parent->nodc; ++i) { - _cf_warn_nodev(__whence, parent->nodv[i], NULL, fmt, ap); + va_list ap1; + va_copy(ap1, ap); + _cf_warn_nodev(__whence, parent->nodv[i], NULL, fmt, ap1); + va_end(ap1); _cf_warn_childrenv(__whence, parent->nodv[i], fmt, ap); } } @@ -673,8 +676,13 @@ void _cf_warn_array_value(struct __sourceloc __whence, const struct cf_om_node * _cf_warn_node(__whence, node, NULL, "array element -- %s", strbuf_str(b)); } -void _cf_warn_list_overflow(struct __sourceloc __whence, const struct cf_om_node *node) +void _cf_warn_list_overflow(struct __sourceloc __whence, const struct cf_om_node *node, const char *fmt, ...) { - _cf_warn_node(__whence, node, NULL, "list overflow"); - _cf_warn_children(__whence, node, "list overflow"); + va_list ap; + va_start(ap, fmt); + _cf_warn_nodev(__whence, node, NULL, fmt, ap); + va_end(ap); + va_start(ap, fmt); + _cf_warn_childrenv(__whence, node, fmt, ap); + va_end(ap); } diff --git a/conf_parse.c b/conf_parse.c index 4bbfd904..b6899868 100644 --- a/conf_parse.c +++ b/conf_parse.c @@ -302,7 +302,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. assert(n == NELS(array->av)); \ result |= CFARRAYOVERFLOW; \ for (; i < node->nodc; ++i) \ - cf_warn_list_overflow(node->nodv[i]); \ + cf_warn_list_overflow(node->nodv[i], "list overflow, only %zu elements allowed", NELS(array->av)); \ } \ array->ac = n; \ qsort(array->av, array->ac, sizeof array->av[0], (int (*)(const void *, const void *)) keycmp); \ diff --git a/tests/config b/tests/config index 2b657383..acb5b1bb 100755 --- a/tests/config +++ b/tests/config @@ -279,6 +279,26 @@ test_InterfaceDropDgramIncompatible() { --error-pattern='config file.*loaded despite defects.*incompatible' } +doc_TooManyValues="Too many config values" +setup_TooManyArgs() { + setup_servald + for i in {0..9}; do + executeOk_servald config set "interfaces.$i.match" "eth$i" + done +} +test_TooManyArgs() { + execute --stderr --executable=$servald config \ + set "interfaces.99.match" "eth11" \ + set "interfaces.99.exclude" "on" \ + set "interfaces.99.port" "1234" \ + set "interfaces.99.broadcast.send" "on" \ + set "interfaces.99.broadcast.route" "on" \ + set "interfaces.99.unicast.send" "on" \ + set "interfaces.99.unicast.route" "on" + tfw_cat --stdout --stderr + assertExitStatus '==' 2 +} + #TODO move to another test script? doc_CmdUsage="Show help usage" test_CmdUsage() {