summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-06-23 15:14:06 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-07-12 15:05:05 +0000
commit04e64062184c93c35bf004b07004ed4676675679 (patch)
treea416a22052116927d980546a04e52699d7022970 /lib/command.c
parent51e156b303174567062db59268bc8afa43ef730f (diff)
lib: Cleanup cmd_execute_command
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/lib/command.c b/lib/command.c
index b5a754fccf..4b571ba75d 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -2599,7 +2599,7 @@ cmd_execute_command_real (vector vline,
int
cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
int vtysh) {
- int ret, saved_ret, tried = 0;
+ int ret, saved_ret = 0;
enum node_type onode, try_node;
onode = try_node = vty->node;
@@ -2615,9 +2615,7 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
shifted_vline = vector_init (vector_count(vline));
/* use memcpy? */
for (index = 1; index < vector_active (vline); index++)
- {
- vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
- }
+ vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
ret = cmd_execute_command_real (shifted_vline, FILTER_RELAXED, vty, cmd);
@@ -2632,24 +2630,22 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
if (vtysh)
return saved_ret;
- /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */
- while ( ret != CMD_SUCCESS && ret != CMD_WARNING
- && vty->node > CONFIG_NODE )
+ if (ret != CMD_SUCCESS && ret != CMD_WARNING)
{
- try_node = node_parent(try_node);
- vty->node = try_node;
- ret = cmd_execute_command_real (vline, FILTER_RELAXED, vty, cmd);
- tried = 1;
- if (ret == CMD_SUCCESS || ret == CMD_WARNING)
- {
- /* succesfull command, leave the node as is */
- return ret;
- }
+ /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */
+ while (vty->node > CONFIG_NODE)
+ {
+ try_node = node_parent(try_node);
+ vty->node = try_node;
+ ret = cmd_execute_command_real (vline, FILTER_RELAXED, vty, cmd);
+ if (ret == CMD_SUCCESS || ret == CMD_WARNING)
+ return ret;
+ }
+ /* no command succeeded, reset the vty to the original node */
+ vty->node = onode;
}
- /* no command succeeded, reset the vty to the original node and
- return the error for this node */
- if ( tried )
- vty->node = onode;
+
+ /* return command status for original node */
return saved_ret;
}