]> git.proxmox.com Git - mirror_frr.git/blob - lib/debug.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / debug.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Debugging utilities.
4 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * Quentin Young
6 */
7 #include <zebra.h>
8 #include "typesafe.h"
9 #include "debug.h"
10 #include "command.h"
11
12 static struct debug_cb_list_head cb_head;
13
14 DECLARE_LIST(debug_cb_list, struct debug_callbacks, item);
15
16 /* All code in this section should be reentrant and MT-safe */
17
18 DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",
19 NO_STR DEBUG_STR "Toggle all debugging output\n")
20 {
21 struct debug_callbacks *cb;
22
23 bool set = !strmatch(argv[0]->text, "no");
24 uint32_t mode = DEBUG_NODE2MODE(vty->node);
25
26 frr_each (debug_cb_list, &cb_head, cb)
27 cb->debug_set_all(mode, set);
28
29 return CMD_SUCCESS;
30 }
31
32 /* ------------------------------------------------------------------------- */
33
34 void debug_init(struct debug_callbacks *cb)
35 {
36 static bool inited = false;
37
38 if (!inited) {
39 inited = true;
40 debug_cb_list_init(&cb_head);
41 }
42
43 debug_cb_list_add_head(&cb_head, cb);
44 }
45
46 void debug_init_cli(void)
47 {
48 install_element(ENABLE_NODE, &debug_all_cmd);
49 install_element(CONFIG_NODE, &debug_all_cmd);
50 }