Arkadiusz Miskiewicz | 15 Jun 15:11

multiple "gnutlses" in single binary

Hello,

Take a look at this example. 

There is one program (let be it php interpreter) that is able to load external 
modules (so modules).

Now we have two external modules - curl and postgresql [1]. Assume both curl 
and postgresql use external libraries (libcurl and libpq) that internally 
also use gnutls.

Both these libraries initialize and deinitialize gnutls on it's own. 
Separately they work fine.

Now it php loads them both at the same time then gnutls initialization happens 
twice (once called by curl module and second time by postgres module) and the 
same happens for deinitialization. In openssl for example double deinit 
causes segfault and is now allowed (a real problem with php + modules btw).

How things look in gnutls? I assume init/deinit also can't be called multiple 
times safely, right?

What can be done in such example to correctly handle gnutls requirements for 
init/deinit? There is only one important thing - the only place where you can 
do anything is php itself, curl and postgresql module but not in libcurl and 
libpq libraries.

My guess is probably that nothing can be done without altering libcurl and 
libpq but even with modifications - does gnutls have api that would handle 
such situation in generic way? Some callbacks maybe...
(Continue reading)

Re: multiple "gnutlses" in single binary

Arkadiusz Miskiewicz wrote:
> Hello,
> 
> Take a look at this example. 
> 
> There is one program (let be it php interpreter) that is able to load external 
> modules (so modules).
> Now we have two external modules - curl and postgresql [1]. Assume both curl 
> and postgresql use external libraries (libcurl and libpq) that internally 
> also use gnutls.
> Both these libraries initialize and deinitialize gnutls on it's own. 
> Separately they work fine.
> Now it php loads them both at the same time then gnutls initialization happens 
> twice (once called by curl module and second time by postgres module) and the 
> same happens for deinitialization. In openssl for example double deinit 
> causes segfault and is now allowed (a real problem with php + modules btw).
> How things look in gnutls? I assume init/deinit also can't be called multiple 
> times safely, right?

No there is no problem as long as they are called in a thread safe way.

regards,
Nikos

Gmane