[OpenSIPS-Users] global variables

Josip Djuricic josip.djuricic at voljatel.hr
Fri Mar 12 14:51:25 CET 2010


In this case we can forget global c variable.

I'm thinking about this solution, building custom module, that will
start as a single process (one fork), and siptrace will be putting all
the data on fifo queue (inside of shared memory) instead of db, and then
this new module will take data from queue and put it in db.

Of-course I could use virtual-db also.


Best regards,

Josip

On Fri, 2010-03-12 at 12:59 +0200, Bogdan-Andrei Iancu wrote:
> 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
> >
> >   
> 
> 





More information about the Users mailing list