]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: only show error codes once
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 8 Jan 2019 21:33:49 +0000 (21:33 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 29 Jul 2019 17:18:18 +0000 (17:18 +0000)
When using `show error` commands, show errors shared between multiple
daemons only once.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/ferr.c
lib/ferr.h
lib/libfrr.c
vtysh/vtysh.c
vtysh/vtysh_main.c

index 65c0cf886d3fbfaf677b144bb6072d87354dd645..8afc926c412fa2a3f8dcf72caedd5b236bde7f48 100644 (file)
@@ -126,10 +126,8 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json)
 
        if (code) {
                ref = log_ref_get(code);
-               if (!ref) {
-                       vty_out(vty, "Code %"PRIu32" - Unknown\n", code);
+               if (!ref)
                        return;
-               }
                listnode_add(errlist, ref);
        }
 
@@ -197,8 +195,6 @@ void log_ref_init(void)
                                   "Error Reference Texts");
        }
        pthread_mutex_unlock(&refs_mtx);
-
-       install_element(VIEW_NODE, &show_error_code_cmd);
 }
 
 void log_ref_fini(void)
@@ -212,6 +208,12 @@ void log_ref_fini(void)
        pthread_mutex_unlock(&refs_mtx);
 }
 
+void log_ref_vty_init(void)
+{
+       install_element(VIEW_NODE, &show_error_code_cmd);
+}
+
+
 const struct ferr *ferr_get_last(ferr_r errval)
 {
        struct ferr *last_error = pthread_getspecific(errkey);
index 93d0ced5389fa2ba537d49b8467b802756c7497b..a89b595e8746104bc2b892c65e244703edd9da04 100644 (file)
@@ -158,6 +158,7 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json);
  */
 void log_ref_init(void);
 void log_ref_fini(void);
+void log_ref_vty_init(void);
 
 /* get error details.
  *
index 3294a612952f2971b567e4708080c95cad0a876c..0fc321d6e028ca1d28cbee757ab0cce53ff609da 100644 (file)
@@ -681,6 +681,7 @@ struct thread_master *frr_init(void)
        log_filter_cmd_init();
 
        log_ref_init();
+       log_ref_vty_init();
        lib_error_init();
 
        yang_init();
index 7a07dab121a4fe69d2018972a06e78602d2aaeb3..5e7f3f1f49470d174a6a02f32d16a22a007dc474 100644 (file)
@@ -46,6 +46,7 @@
 #include "command_graph.h"
 #include "frrstr.h"
 #include "json.h"
+#include "ferr.h"
 
 DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")
 
@@ -2394,17 +2395,28 @@ DEFUN (vtysh_show_error_code,
        "Information on all errors\n"
        JSON_STR)
 {
-       char *fcmd = argv_concat(argv, argc, 0);
-       char cmd[256];
-       int rv;
+       uint32_t arg = 0;
 
-       snprintf(cmd, sizeof(cmd), "do %s", fcmd);
+       if (!strmatch(argv[2]->text, "all"))
+               arg = strtoul(argv[2]->arg, NULL, 10);
 
-       /* FIXME: Needs to determine which daemon to send to via code ranges */
-       rv = show_per_daemon(cmd, "");
+       /* If it's not a shared code, send it to all the daemons */
+       if (arg < LIB_FERR_START || arg > LIB_FERR_END) {
+               char *fcmd = argv_concat(argv, argc, 0);
+               char cmd[256];
+               snprintf(cmd, sizeof(cmd), "do %s", fcmd);
+               show_per_daemon(cmd, "");
+               XFREE(MTYPE_TMP, fcmd);
+               /* Otherwise, print it ourselves to avoid duplication */
+       } else {
+               bool json = strmatch(argv[argc - 1]->text, "json");
+               if (!strmatch(argv[2]->text, "all"))
+                       arg = strtoul(argv[2]->arg, NULL, 10);
+
+               log_ref_display(vty, arg, json);
+       }
 
-       XFREE(MTYPE_TMP, fcmd);
-       return rv;
+       return CMD_SUCCESS;
 }
 
 /* Memory */
index 96674601891568b01f9e3bd0d53960df9b6f9ab1..d536263db0d84baef8b259f140c5a7b074dc9ea9 100644 (file)
@@ -47,6 +47,8 @@
 #include "linklist.h"
 #include "memory_vty.h"
 #include "libfrr.h"
+#include "ferr.h"
+#include "lib_errors.h"
 
 #include "vtysh/vtysh.h"
 #include "vtysh/vtysh_user.h"
@@ -461,6 +463,9 @@ int main(int argc, char **argv, char **env)
                vtysh_read_config(vtysh_config);
                suid_off();
        }
+       /* Error code library system */
+       log_ref_init();
+       lib_error_init();
 
        if (markfile) {
                if (!inputfile) {