Module: sip-router
Branch: master
Commit: feb00c92297eb2d4520a59f1a676cf998add1b5d
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=feb00c9…
Author: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Committer: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Date: Thu May 23 08:58:38 2013 +0200
modules/debugger: use cfg framework to be able to activate/deactivate debug per module.
mod_hash_size has to be set with a value > 0 on startup.
---
modules/debugger/debugger_api.c | 20 +++++++++++++++++---
modules/debugger/debugger_api.h | 2 +-
modules/debugger/debugger_mod.c | 24 +++++++++++++++++-------
modules/debugger/doc/debugger_admin.xml | 4 ++--
4 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/modules/debugger/debugger_api.c b/modules/debugger/debugger_api.c
index 4a5828d..390d92d 100644
--- a/modules/debugger/debugger_api.c
+++ b/modules/debugger/debugger_api.c
@@ -36,9 +36,10 @@
#include "../../route_struct.h"
#include "../../mem/shm_mem.h"
#include "../../locking.h"
-
+
#include "debugger_act.h"
#include "debugger_api.h"
+#include "debugger_config.h"
#define DBG_CMD_SIZE 256
@@ -914,10 +915,10 @@ static unsigned int _dbg_mod_table_size = 0;
/**
*
*/
-int dbg_init_mod_levels(int dbg_mod_level, int dbg_mod_hash_size)
+int dbg_init_mod_levels(int dbg_mod_hash_size)
{
int i;
- if(dbg_mod_level==0 || dbg_mod_hash_size<=0)
+ if(dbg_mod_hash_size<=0)
return 0;
if(_dbg_mod_table!=NULL)
return 0;
@@ -1067,6 +1068,9 @@ int dbg_get_mod_debug_level(char *mname, int mnlen, int *mlevel)
if(_dbg_mod_table==NULL)
return -1;
+ if(cfg_get(dbg, dbg_cfg, mod_level_mode)==0)
+ return -1;
+
if(_dbg_get_mod_debug_level!=0)
return -1;
_dbg_get_mod_debug_level = 1;
@@ -1104,3 +1108,13 @@ void dbg_enable_mod_levels(void)
return;
set_module_debug_level_cb(dbg_get_mod_debug_level);
}
+
+int dbg_level_mode_fixup(void *temp_handle,
+ str *group_name, str *var_name, void **value){
+ if(_dbg_mod_table==NULL)
+ {
+ LM_ERR("mod_hash_size must be set on start\n");
+ return -1;
+ }
+ return 0;
+}
diff --git a/modules/debugger/debugger_api.h b/modules/debugger/debugger_api.h
index 9af8cf6..1060c95 100644
--- a/modules/debugger/debugger_api.h
+++ b/modules/debugger/debugger_api.h
@@ -33,7 +33,7 @@ int dbg_init_pid_list(void);
int dbg_init_mypid(void);
int dbg_init_rpc(void);
-int dbg_init_mod_levels(int _dbg_mod_level, int _dbg_mod_hash_size);
+int dbg_init_mod_levels(int _dbg_mod_hash_size);
int dbg_set_mod_debug_level(char *mname, int mnlen, int *mlevel);
void dbg_enable_mod_levels(void);
diff --git a/modules/debugger/debugger_mod.c b/modules/debugger/debugger_mod.c
index 98d317b..8b511bb 100644
--- a/modules/debugger/debugger_mod.c
+++ b/modules/debugger/debugger_mod.c
@@ -35,6 +35,7 @@
#include "../../shm_init.h"
#include "debugger_api.h"
+#include "debugger_config.h"
MODULE_VERSION
@@ -57,9 +58,6 @@ extern int _dbg_step_loops;
static char * _dbg_cfgtrace_facility_str = 0;
-static int _dbg_mod_hash_size = 0;
-static int _dbg_mod_level = 0;
-
static cmd_export_t cmds[]={
{"dbg_breakpoint", (cmd_function)w_dbg_breakpoint, 1,
fixup_dbg_breakpoint, 0, ANY_ROUTE},
@@ -74,8 +72,8 @@ static param_export_t params[]={
{"log_prefix", STR_PARAM, &_dbg_cfgtrace_prefix},
{"step_usleep", INT_PARAM, &_dbg_step_usleep},
{"step_loops", INT_PARAM, &_dbg_step_loops},
- {"mod_hash_size", INT_PARAM, &_dbg_mod_hash_size},
- {"mod_level_mode", INT_PARAM, &_dbg_mod_level},
+ {"mod_hash_size", INT_PARAM, &default_dbg_cfg.mod_hash_size},
+ {"mod_level_mode", INT_PARAM, &default_dbg_cfg.mod_level_mode},
{"mod_level", STR_PARAM|USE_FUNC_PARAM, (void*)dbg_mod_level_param},
{0, 0, 0}
};
@@ -120,7 +118,16 @@ static int mod_init(void)
return -1;
}
- if(dbg_init_mod_levels(_dbg_mod_level, _dbg_mod_hash_size)<0)
+ if(cfg_declare("dbg", dbg_cfg_def, &default_dbg_cfg, cfg_sizeof(dbg),
&dbg_cfg))
+ {
+ LM_ERR("Fail to declare the configuration\n");
+ return -1;
+ }
+ LM_DBG("cfg level_mode:%d hash_size:%d\n",
+ cfg_get(dbg, dbg_cfg, mod_level_mode),
+ cfg_get(dbg, dbg_cfg, mod_hash_size));
+
+ if(dbg_init_mod_levels(cfg_get(dbg, dbg_cfg, mod_hash_size))<0)
{
LM_ERR("failed to init per module log level\n");
return -1;
@@ -210,7 +217,10 @@ static int dbg_mod_level_param(modparam_t type, void *val)
}
s.s = (char*)val;
s.len = p - s.s;
- if(dbg_init_mod_levels(_dbg_mod_level, _dbg_mod_hash_size)<0)
+ LM_DBG("cfg level_mode:%d hash_size:%d\n",
+ cfg_get(dbg, dbg_cfg, mod_level_mode),
+ cfg_get(dbg, dbg_cfg, mod_hash_size));
+ if(dbg_init_mod_levels(cfg_get(dbg, dbg_cfg, mod_hash_size))<0)
{
LM_ERR("failed to init per module log level\n");
return -1;
diff --git a/modules/debugger/doc/debugger_admin.xml
b/modules/debugger/doc/debugger_admin.xml
index af56f83..e97e4bf 100644
--- a/modules/debugger/doc/debugger_admin.xml
+++ b/modules/debugger/doc/debugger_admin.xml
@@ -227,7 +227,7 @@ modparam("debugger", "step_loops", 100)
<title><varname>mod_hash_size</varname> (int)</title>
<para>
Used to compute power of two as size of internal hash table to store levels
- per module (e.g., if its set to 4, internal hash table has 16 slots).
+ per module (e.g., if its set to 4, internal hash table has 16 slots). This parameter is
accesible readonly via the ser cfg framework.
</para>
<para>
<emphasis>
@@ -247,7 +247,7 @@ modparam("debugger", "mod_hash_size", 5)
<section>
<title><varname>mod_level_mode</varname> (int)</title>
<para>
- Enable or disable per module log level (0 - disabled, 1 - enabled).
+ Enable or disable per module log level (0 - disabled, 1 - enabled). This
parameter is tunable via the ser cfg framework.
</para>
<para>
<emphasis>