Ticket #99 (closed defect)
libssh2 library is not thread safe
|Reported by:||anonymous||Owned by:||bagder|
By default, there is no "-D_REENTRANT" flag passed to the C preprocessor (nor any -mt (Sun Studio) or -pthreads (gcc) option to the C compiler).
Note: I'm using libssh2 on Solaris 9/10, using Sun Studio 12.
Referencing errno in many pieces of code makes the whole library not thread safe (libssh2_session_startup() for example). There are many EAGAIN errors that are now thrown internally (because of new non-blocking sockets in 1.1), but unfortunately, the errno value is not correctly accessed, leading to undefined behaviour. This can be "easily" reproduced using something like (compiled in a thread safe manner):
Th.1: set errno
Th.1: detach thread 2
Th.2: establish an SSH connection. libssh2_session_startup() will usually fail.
I've passed CPPFLAGS="-D_REENTRANT" to the configure script, and things seem now to be OK.
Miscellaneous defects of the "configure" script:
- Specifying LDFLAGS="-mt -pthreads" does not pass these options to the ld linker.
- Specifying --disable-debug still compiles with "-g".