From 04e64062184c93c35bf004b07004ed4676675679 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 23 Jun 2016 15:14:06 +0000 Subject: [PATCH] lib: Cleanup cmd_execute_command Signed-off-by: Quentin Young --- lib/command.c | 36 ++++++++++++++++-------------------- 1 file 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; } -- 2.39.5