]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/command.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / command.c
index ee5a3889e8c0ca7e631a79c6108d9c080b7544c4..099563721902666f493661f173f2a0b90ea47b97 100644 (file)
@@ -17,7 +17,7 @@
 #include "memory.h"
 #include "log.h"
 #include "log_vty.h"
-#include "thread.h"
+#include "frrevent.h"
 #include "vector.h"
 #include "linklist.h"
 #include "vty.h"
@@ -31,6 +31,8 @@
 #include "jhash.h"
 #include "hook.h"
 #include "lib_errors.h"
+#include "mgmt_be_client.h"
+#include "mgmt_fe_client.h"
 #include "northbound_cli.h"
 #include "network.h"
 #include "routemap.h"
@@ -733,9 +735,13 @@ char *cmd_variable_comp2str(vector comps, unsigned short cols)
                char *item = vector_slot(comps, j);
                itemlen = strlen(item);
 
-               if (cs + itemlen + AUTOCOMP_INDENT + 3 >= bsz)
-                       buf = XREALLOC(MTYPE_TMP, buf, (bsz *= 2));
+               size_t next_sz = cs + itemlen + AUTOCOMP_INDENT + 3;
 
+               if (next_sz > bsz) {
+                       /* Make sure the buf size is large enough */
+                       bsz = next_sz;
+                       buf = XREALLOC(MTYPE_TMP, buf, bsz);
+               }
                if (lc + itemlen + 1 >= cols) {
                        cs += snprintf(&buf[cs], bsz - cs, "\n%*s",
                                       AUTOCOMP_INDENT, "");
@@ -1281,6 +1287,7 @@ int command_config_read_one_line(struct vty *vty,
 
                memcpy(ve->error_buf, vty->buf, VTY_BUFSIZ);
                ve->line_num = line_num;
+               ve->cmd_ret = ret;
                if (!vty->error)
                        vty->error = list_new();
 
@@ -1301,6 +1308,14 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num)
        while (fgets(vty->buf, VTY_BUFSIZ, fp)) {
                ++(*line_num);
 
+               if (vty_log_commands) {
+                       int len = strlen(vty->buf);
+
+                       /* now log the command */
+                       zlog_notice("config-from-file# %.*s", len ? len - 1 : 0,
+                                   vty->buf);
+               }
+
                ret = command_config_read_one_line(vty, NULL, *line_num, 0);
 
                if (ret != CMD_SUCCESS && ret != CMD_WARNING
@@ -2438,6 +2453,8 @@ const char *host_config_get(void)
 void cmd_show_lib_debugs(struct vty *vty)
 {
        route_map_show_debug(vty);
+       mgmt_debug_be_client_show_debug(vty);
+       mgmt_debug_fe_client_show_debug(vty);
 }
 
 void install_default(enum node_type node)
@@ -2542,7 +2559,7 @@ void cmd_init(int terminal)
 
                install_default(CONFIG_NODE);
 
-               thread_cmd_init();
+               event_cmd_init();
                workqueue_cmd_init();
                hash_cmd_init();
        }
@@ -2596,9 +2613,7 @@ void cmd_terminate(void)
                                // well
                                graph_delete_graph(cmd_node->cmdgraph);
                                vector_free(cmd_node->cmd_vector);
-                               hash_clean(cmd_node->cmd_hash, NULL);
-                               hash_free(cmd_node->cmd_hash);
-                               cmd_node->cmd_hash = NULL;
+                               hash_clean_and_free(&cmd_node->cmd_hash, NULL);
                        }
 
                vector_free(cmdvec);