[OpenSIPS-Users] global variables

Bogdan-Andrei Iancu bogdan at voice-system.ro
Fri Mar 12 11:59:46 CET 2010


Hi Josip,

Josip Djuricic wrote:
> 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,
so a global C variable, right ?
>  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.
It is the same processes ? as the variable will has independent values 
in each processes (check the pid in the log message)
>  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.
>   
no, the idea is that the siptrace module code is running in multiple 
processes (in opensips worker processes).
> If that is the case, what would you suggest? I would then need to use 
> interprocess communication, perhaps I could reuse something from opensips?
>   
use the shared memory to create at startup a variable to be shared 
between all procs.

Regards,
Bogdan
> 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
>>
>>     
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
>   


-- 
Bogdan-Andrei Iancu
www.voice-system.ro




More information about the Users mailing list