Skip to content

Commit

Permalink
cfgutils: more log messages for locking functions
Browse files Browse the repository at this point in the history
- 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)

(cherry picked from commit 3ce65db)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent 2ff8e36 commit 5b727e0
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/modules/cfgutils/cfgutils.c
Expand Up @@ -652,9 +652,15 @@ static int dbg_shm_summary(struct sip_msg* msg, char* foo, char* bar)
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 */
Expand Down Expand Up @@ -696,8 +702,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;
}
Expand All @@ -706,22 +714,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);
}

Expand Down Expand Up @@ -803,12 +805,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;
}
Expand Down

0 comments on commit 5b727e0

Please sign in to comment.