]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/ferr.c
zebra: Refactor kernel_rtm to be a bit smarter about how it handles options
[mirror_frr.git] / lib / ferr.c
index d09c41fae02c5fbee125ec688ebceada6b51bfe9..e18597afb07c0a92537c26909516b1b4faa47983 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>
@@ -60,22 +64,22 @@ static void err_key_fini(void)
 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 ferr_ref *f_a = a;
-       const struct ferr_ref *f_b = b;
+       const struct log_ref *f_a = a;
+       const struct log_ref *f_b = b;
 
        return f_a->code == f_b->code;
 }
 
 static inline unsigned int ferr_hash_key(void *a)
 {
-       struct ferr_ref *f = a;
+       struct log_ref *f = a;
 
        return f->code;
 }
 
-void ferr_ref_add(struct ferr_ref *ref)
+void log_ref_add(struct log_ref *ref)
 {
        uint32_t i = 0;
 
@@ -89,10 +93,10 @@ void ferr_ref_add(struct ferr_ref *ref)
        pthread_mutex_unlock(&refs_mtx);
 }
 
-struct ferr_ref *ferr_ref_get(uint32_t code)
+struct log_ref *log_ref_get(uint32_t code)
 {
-       struct ferr_ref holder;
-       struct ferr_ref *ref;
+       struct log_ref holder;
+       struct log_ref *ref;
 
        holder.code = code;
        pthread_mutex_lock(&refs_mtx);
@@ -104,10 +108,10 @@ struct ferr_ref *ferr_ref_get(uint32_t code)
        return ref;
 }
 
-void ferr_ref_display(struct vty *vty, uint32_t code, bool json)
+void log_ref_display(struct vty *vty, uint32_t code, bool json)
 {
-       struct ferr_ref *ref;
-       struct json_object *top, *obj;
+       struct log_ref *ref;
+       struct json_object *top = NULL, *obj = NULL;
        struct list *errlist;
        struct listnode *ln;
 
@@ -121,7 +125,7 @@ void ferr_ref_display(struct vty *vty, uint32_t code, bool json)
        pthread_mutex_unlock(&refs_mtx);
 
        if (code) {
-               ref = ferr_ref_get(code);
+               ref = log_ref_get(code);
                if (!ref) {
                        vty_out(vty, "Code %"PRIu32" - Unknown\n", code);
                        return;
@@ -132,6 +136,7 @@ void ferr_ref_display(struct vty *vty, uint32_t code, bool json)
        for (ALL_LIST_ELEMENTS_RO(errlist, ln, ref)) {
                if (json) {
                        char key[11];
+
                        snprintf(key, sizeof(key), "%"PRIu32, ref->code);
                        obj = json_object_new_object();
                        json_object_string_add(obj, "title", ref->title);
@@ -143,14 +148,15 @@ void ferr_ref_display(struct vty *vty, uint32_t code, bool json)
                } else {
                        char pbuf[256];
                        char ubuf[256];
+
                        snprintf(pbuf, sizeof(pbuf), "\nError %"PRIu32" - %s",
-                                code, ref->title);
+                                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\nRecommendation:\n%s\n",
-                               ref->description, ref->suggestion);
+                       vty_out(vty, "Description:\n%s\n\n", ref->description);
+                       vty_out(vty, "Recommendation:\n%s\n", ref->suggestion);
                }
        }
 
@@ -161,7 +167,7 @@ void ferr_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,
@@ -175,14 +181,15 @@ DEFUN_NOSH(show_error_code,
 {
        bool json = strmatch(argv[argc-1]->text, "json");
        uint32_t arg = 0;
+
        if (!strmatch(argv[2]->text, "all"))
                arg = strtoul(argv[2]->arg, NULL, 10);
 
-       ferr_ref_display(vty, arg, json);
+       log_ref_display(vty, arg, json);
        return CMD_SUCCESS;
 }
 
-void ferr_ref_init(void)
+void log_ref_init(void)
 {
        pthread_mutex_lock(&refs_mtx);
        {
@@ -194,10 +201,11 @@ void ferr_ref_init(void)
        install_element(VIEW_NODE, &show_error_code_cmd);
 }
 
-void ferr_ref_fini(void)
+void log_ref_fini(void)
 {
        pthread_mutex_lock(&refs_mtx);
        {
+               hash_clean(refs, NULL);
                hash_free(refs);
                refs = NULL;
        }