[OpenSIPS-Users] global variables

Josip Djuricic josip.djuricic at voljatel.hr
Wed Mar 10 23:42:29 CET 2010


Sorry I missed this email,

I'll think about using db_virtual, but back to global vars issue, for a 
test I defined just a global counter variable, and created new function 
inside siptrace module, so every time a siptrace function is called I 
also call this function and do counter ++. since counter is defined 
outside of the function, it should be defined as global variable, so 
I've outputed with LM_INFO value of counter and it's always 1, sometime 
it gets pass that value, but on the next call it's 1 again. Perhaps I'm 
thinking wrong and siptrace module is not having it's own fork, but 
instead loads inside other forks? That would explain this behaviour.

If that is the case, what would you suggest? I would then need to use 
interprocess communication, perhaps I could reuse something from opensips?

Best regards,

Josip

Bogdan-Andrei Iancu wrote:
> Hi Josip,
>
> Josip Djuricic wrote:
>> Hi,
>>
>> one probably stupid question, I'm customizing siptrace module further,
>> so I am adding queue for db writing, in case we loose db connectivity
>> and threads for popping the queue and writing to db.
>>   
> why don't you use the new db_virtual module with a failover 
> configuration: define a new virtual db connection that has behind a 
> primary mysql conn and a secondary (failover only) flatstore/dbtext 
> conn. So, if DB fails, you will start writing to a local file.
>> Written almost everything, but just to be sure, if I use global variable
>> for linked list, will they keep the values until opensips ends, or will
>> they always be reinitialized, because for test purposes I defined
>> counter but it's always initialized to default value.
>>   
> To be honest I do not advices using thread in current opensips as you 
> have multiple processes already. And the combination of threads and 
> processes may be unpredictable.
> Anyhow, regarding your question - the global vars are init only at 
> startup time - but note that "global" is as visibility in the code and 
> not global "in all processes". Each process will have its own copy of 
> the var.
>
> Regards,
> Bogdan
>




More information about the Users mailing list