summaryrefslogtreecommitdiff
path: root/lib/debug.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2024-03-26 16:54:54 +0200
committerMark Stapp <mjs@cisco.com>2024-08-27 09:53:02 -0400
commit5dac6961540422a1ca139fae8c5ea9e5a437c4ba (patch)
tree3ff27afc04b9605f832c747b82449b58d5aa5455 /lib/debug.c
parent1797b7eefc730bb4f5aec08f130861650c61dd97 (diff)
lib: rework debug init
The debug library allows to register a `debug_set_all` callback which should enable all debugs in a daemon. This callback is implemented exactly the same in each daemon. Instead of duplicating the code, rework the lib to allow registration of each debug type, and implement the common code only once in the lib. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/debug.c')
-rw-r--r--lib/debug.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/lib/debug.c b/lib/debug.c
index 757a47ab99..5f9109b3f1 100644
--- a/lib/debug.c
+++ b/lib/debug.c
@@ -9,42 +9,44 @@
#include "debug.h"
#include "command.h"
-static struct debug_cb_list_head cb_head;
+static struct debug_list_head debug_head;
-DECLARE_LIST(debug_cb_list, struct debug_callbacks, item);
+DECLARE_LIST(debug_list, struct debug, item);
/* All code in this section should be reentrant and MT-safe */
-DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",
- NO_STR DEBUG_STR "Toggle all debugging output\n")
+DEFUN_NOSH (debug_all,
+ debug_all_cmd,
+ "[no] debug all",
+ NO_STR DEBUG_STR
+ "Toggle all debugging output\n")
{
- struct debug_callbacks *cb;
-
+ struct debug *debug;
bool set = !strmatch(argv[0]->text, "no");
uint32_t mode = DEBUG_NODE2MODE(vty->node);
- frr_each (debug_cb_list, &cb_head, cb)
- cb->debug_set_all(mode, set);
+ frr_each (debug_list, &debug_head, debug) {
+ DEBUG_MODE_SET(debug, mode, set);
+
+ /* If all modes have been turned off, don't preserve options. */
+ if (!DEBUG_MODE_CHECK(debug, DEBUG_MODE_ALL))
+ DEBUG_CLEAR(debug);
+ }
return CMD_SUCCESS;
}
/* ------------------------------------------------------------------------- */
-void debug_init(struct debug_callbacks *cb)
+void debug_install(struct debug *debug)
{
- static bool inited = false;
-
- if (!inited) {
- inited = true;
- debug_cb_list_init(&cb_head);
- }
-
- debug_cb_list_add_head(&cb_head, cb);
+ debug_list_add_tail(&debug_head, debug);
}
-void debug_init_cli(void)
+void debug_init(void)
{
+ debug_list_init(&debug_head);
+
install_element(ENABLE_NODE, &debug_all_cmd);
install_element(CONFIG_NODE, &debug_all_cmd);
}