]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: better warnings for install_element
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 23 Aug 2017 15:06:24 +0000 (17:06 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 23 Aug 2017 22:18:53 +0000 (00:18 +0200)
Also fixes misuse of vector_slot() - that one doesn't check for access
beyond end of vector...

And print node names in grammar sandbox "printall".

Fixes: #543
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/command.c
lib/grammar_sandbox.c

index f47bf81452c656e91542589b92173dbc46d6c013..c86025a3bd12d0251f60ac12b1cfbcd3d944df7e 100644 (file)
@@ -360,21 +360,23 @@ void install_element(enum node_type ntype, struct cmd_element *cmd)
                return;
        }
 
-       cnode = vector_slot(cmdvec, ntype);
+       cnode = vector_lookup(cmdvec, ntype);
 
        if (cnode == NULL) {
                fprintf(stderr,
-                       "Command node %d doesn't exist, please check it\n",
-                       ntype);
-               fprintf(stderr,
-                       "Have you called install_node before this install_element?\n");
+                       "%s[%s]:\n"
+                       "\tnode %d (%s) does not exist.\n"
+                       "\tplease call install_node() before install_element()\n",
+                       cmd->name, cmd->string, ntype, node_names[ntype]);
                exit(EXIT_FAILURE);
        }
 
        if (hash_lookup(cnode->cmd_hash, cmd) != NULL) {
                fprintf(stderr,
-                       "Multiple command installs to node %d of command:\n%s\n",
-                       ntype, cmd->string);
+                       "%s[%s]:\n"
+                       "\tnode %d (%s) already has this command installed.\n"
+                       "\tduplicate install_element call?\n",
+                       cmd->name, cmd->string, ntype, node_names[ntype]);
                return;
        }
 
@@ -407,21 +409,23 @@ void uninstall_element(enum node_type ntype, struct cmd_element *cmd)
                return;
        }
 
-       cnode = vector_slot(cmdvec, ntype);
+       cnode = vector_lookup(cmdvec, ntype);
 
        if (cnode == NULL) {
                fprintf(stderr,
-                       "Command node %d doesn't exist, please check it\n",
-                       ntype);
-               fprintf(stderr,
-                       "Have you called install_node before this install_element?\n");
+                       "%s[%s]:\n"
+                       "\tnode %d (%s) does not exist.\n"
+                       "\tplease call install_node() before uninstall_element()\n",
+                       cmd->name, cmd->string, ntype, node_names[ntype]);
                exit(EXIT_FAILURE);
        }
 
        if (hash_release(cnode->cmd_hash, cmd) == NULL) {
                fprintf(stderr,
-                       "Trying to uninstall non-installed command (node %d):\n%s\n",
-                       ntype, cmd->string);
+                       "%s[%s]:\n"
+                       "\tnode %d (%s) does not have this command installed.\n"
+                       "\tduplicate uninstall_element call?\n",
+                       cmd->name, cmd->string, ntype, node_names[ntype]);
                return;
        }
 
index 96ecfa44d385d7f090217c9f0ecb4952c74390e8..3c6396f3470494204b03f286eb1e1a2062105b97 100644 (file)
@@ -404,7 +404,8 @@ DEFUN (grammar_findambig,
                        nodegraph = cnode->cmdgraph;
                        if (!nodegraph)
                                continue;
-                       vty_out(vty, "scanning node %d\n", scannode - 1);
+                       vty_out(vty, "scanning node %d (%s)\n",
+                               scannode - 1, node_names[scannode - 1]);
                }
 
                commands = cmd_graph_permutations(nodegraph);