]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/ferr.c
Merge pull request #5104 from opensourcerouting/route-map-nbv2
[mirror_frr.git] / lib / ferr.c
index bf89cc7f461e83bb9118891fb45d880831d6edfd..ccf63dea17986260dd56247013abd58b5eafacc4 100644 (file)
@@ -33,6 +33,7 @@
 #include "command.h"
 #include "json.h"
 #include "linklist.h"
+#include "frr_pthread.h"
 
 DEFINE_MTYPE_STATIC(LIB, ERRINFO, "error information")
 
@@ -61,10 +62,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;
@@ -72,9 +73,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;
 }
@@ -83,14 +84,12 @@ void log_ref_add(struct log_ref *ref)
 {
        uint32_t i = 0;
 
-       pthread_mutex_lock(&refs_mtx);
-       {
+       frr_with_mutex(&refs_mtx) {
                while (ref[i].code != END_FERR) {
                        hash_get(refs, &ref[i], hash_alloc_intern);
                        i++;
                }
        }
-       pthread_mutex_unlock(&refs_mtx);
 }
 
 struct log_ref *log_ref_get(uint32_t code)
@@ -99,11 +98,9 @@ struct log_ref *log_ref_get(uint32_t code)
        struct log_ref *ref;
 
        holder.code = code;
-       pthread_mutex_lock(&refs_mtx);
-       {
+       frr_with_mutex(&refs_mtx) {
                ref = hash_lookup(refs, &holder);
        }
-       pthread_mutex_unlock(&refs_mtx);
 
        return ref;
 }
@@ -118,18 +115,14 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json)
        if (json)
                top = json_object_new_object();
 
-       pthread_mutex_lock(&refs_mtx);
-       {
+       frr_with_mutex(&refs_mtx) {
                errlist = code ? list_new() : hash_to_list(refs);
        }
-       pthread_mutex_unlock(&refs_mtx);
 
        if (code) {
                ref = log_ref_get(code);
-               if (!ref) {
-                       vty_out(vty, "Code %"PRIu32" - Unknown\n", code);
+               if (!ref)
                        return;
-               }
                listnode_add(errlist, ref);
        }
 
@@ -172,7 +165,7 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json)
 
 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"
@@ -191,27 +184,27 @@ DEFUN_NOSH(show_error_code,
 
 void log_ref_init(void)
 {
-       pthread_mutex_lock(&refs_mtx);
-       {
+       frr_with_mutex(&refs_mtx) {
                refs = hash_create(ferr_hash_key, ferr_hash_cmp,
                                   "Error Reference Texts");
        }
-       pthread_mutex_unlock(&refs_mtx);
-
-       install_element(VIEW_NODE, &show_error_code_cmd);
 }
 
 void log_ref_fini(void)
 {
-       pthread_mutex_lock(&refs_mtx);
-       {
+       frr_with_mutex(&refs_mtx) {
                hash_clean(refs, NULL);
                hash_free(refs);
                refs = NULL;
        }
-       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);