]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/ferr.c
Merge pull request #4847 from vivek-cumulus/evpn-route-import-fix
[mirror_frr.git] / lib / ferr.c
index d1b9d514b468e8d7d63159644d0b68e3ef0efa38..fd5fb50172e07f902c4ffa983a22586dd017cc72 100644 (file)
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
@@ -57,10 +61,10 @@ static void err_key_fini(void)
 /*
  * Global shared hash table holding reference text for all defined errors.
  */
-pthread_mutex_t refs_mtx = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t refs_mtx = PTHREAD_MUTEX_INITIALIZER;
 struct hash *refs;
 
-static int ferr_hash_cmp(const void *a, const void *b)
+static bool ferr_hash_cmp(const void *a, const void *b)
 {
        const struct log_ref *f_a = a;
        const struct log_ref *f_b = b;
@@ -68,9 +72,9 @@ static int ferr_hash_cmp(const void *a, const void *b)
        return f_a->code == f_b->code;
 }
 
-static inline unsigned int ferr_hash_key(void *a)
+static inline unsigned int ferr_hash_key(const void *a)
 {
-       struct log_ref *f = a;
+       const struct log_ref *f = a;
 
        return f->code;
 }
@@ -107,7 +111,7 @@ struct log_ref *log_ref_get(uint32_t code)
 void log_ref_display(struct vty *vty, uint32_t code, bool json)
 {
        struct log_ref *ref;
-       struct json_object *top, *obj;
+       struct json_object *top = NULL, *obj = NULL;
        struct list *errlist;
        struct listnode *ln;
 
@@ -122,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);
        }
 
@@ -148,7 +150,7 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json)
                        snprintf(pbuf, sizeof(pbuf), "\nError %"PRIu32" - %s",
                                 ref->code, ref->title);
                        memset(ubuf, '=', strlen(pbuf));
-                       ubuf[sizeof(ubuf) - 1] = '\0';
+                       ubuf[strlen(pbuf)] = '\0';
 
                        vty_out(vty, "%s\n%s\n", pbuf, ubuf);
                        vty_out(vty, "Description:\n%s\n\n", ref->description);
@@ -163,12 +165,12 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json)
                json_object_free(top);
        }
 
-       list_delete_and_null(&errlist);
+       list_delete(&errlist);
 }
 
 DEFUN_NOSH(show_error_code,
           show_error_code_cmd,
-          "show error <(1-4294967296)|all> [json]",
+          "show error <(1-4294967295)|all> [json]",
           SHOW_STR
           "Information on errors\n"
           "Error code to get info about\n"
@@ -193,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)
@@ -208,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);