Module: kamailio
Branch: master
Commit: 3ce65db8747ad7b382824f389c2b782a76dbb7a1
URL:
https://github.com/kamailio/kamailio/commit/3ce65db8747ad7b382824f389c2b782…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-07-03T17:02:02+02:00
cfgutils: more log messages for locking functions
- it was silent if locks set was not initialized properly which could
mislead at runtime, but not showing any error message
- if locks set size is too big, set it to 14 (this is used as power of 2)
---
Modified: src/modules/cfgutils/cfgutils.c
---
Diff:
https://github.com/kamailio/kamailio/commit/3ce65db8747ad7b382824f389c2b782…
Patch:
https://github.com/kamailio/kamailio/commit/3ce65db8747ad7b382824f389c2b782…
---
diff --git a/src/modules/cfgutils/cfgutils.c b/src/modules/cfgutils/cfgutils.c
index 0b72186546..ca7bf77ae3 100644
--- a/src/modules/cfgutils/cfgutils.c
+++ b/src/modules/cfgutils/cfgutils.c
@@ -705,9 +705,15 @@ static int ki_shm_summary(sip_msg_t* msg)
static int cfg_lock_helper(str *lkey, int mode)
{
unsigned int pos;
+
+ if(_cfg_lock_set==NULL) {
+ LM_ERR("lock set not initialized (attempt to do op: %d on: %.*s)\n",
+ mode, lkey->len, lkey->s);
+ return -1;
+ }
pos = core_case_hash(lkey, 0, _cfg_lock_size);
- LM_DBG("cfg_lock mode %d on %u\n", mode, pos);
+ LM_DBG("cfg_lock mode %d on %u (%.*s)\n", mode, pos, lkey->len,
lkey->s);
if(mode==0) {
/* Lock */
@@ -749,8 +755,10 @@ static int cfg_trylock(str *lkey)
static int w_cfg_lock_wrapper(struct sip_msg *msg, gparam_p key, int mode)
{
str s;
- if(fixup_get_svalue(msg, key, &s)!=0)
- {
+ if(key==NULL) {
+ return -1;
+ }
+ if(fixup_get_svalue(msg, key, &s)!=0) {
LM_ERR("cannot get first parameter\n");
return -1;
}
@@ -759,22 +767,16 @@ static int w_cfg_lock_wrapper(struct sip_msg *msg, gparam_p key, int
mode)
static int w_cfg_lock(struct sip_msg *msg, char *key, char *s2)
{
- if(_cfg_lock_set==NULL || key==NULL)
- return -1;
return w_cfg_lock_wrapper(msg, (gparam_p)key, 0);
}
static int w_cfg_unlock(struct sip_msg *msg, char *key, char *s2)
{
- if(_cfg_lock_set==NULL || key==NULL)
- return -1;
return w_cfg_lock_wrapper(msg, (gparam_p)key, 1);
}
static int w_cfg_trylock(struct sip_msg *msg, char *key, char *s2)
{
- if(_cfg_lock_set==NULL || key==NULL)
- return -1;
return w_cfg_lock_wrapper(msg, (gparam_p)key, 2);
}
@@ -856,12 +858,15 @@ static int mod_init(void)
lock_dealloc(gflags_lock);
return -1;
}
- if(_cfg_lock_size>0 && _cfg_lock_size<=10)
- {
+ if(_cfg_lock_size>0) {
+ if(_cfg_lock_size>14) {
+ LM_WARN("lock set size too large (%d), making it 14\n",
+ _cfg_lock_size);
+ _cfg_lock_size = 14;
+ }
_cfg_lock_size = 1<<_cfg_lock_size;
_cfg_lock_set = lock_set_alloc(_cfg_lock_size);
- if(_cfg_lock_set==NULL || lock_set_init(_cfg_lock_set)==NULL)
- {
+ if(_cfg_lock_set==NULL || lock_set_init(_cfg_lock_set)==NULL) {
LM_ERR("cannot initiate lock set\n");
return -1;
}