Subject: Re: [libssh2] Does sftp work in a multi-threaded program? (PROBLEM SOLVED)

Re: [libssh2] Does sftp work in a multi-threaded program? (PROBLEM SOLVED)

From: James Housley <>
Date: Thu, 7 Jun 2007 20:43:03 -0400

On Jun 7, 2007, at 3:15 PM, Gutjahr, Troy wrote:

> I tried my test program with libssh2-0.14. It works. libssh2_sftp_init
> succeeds in both the main thread and a second thread.
> I suspect that the problem has been exposed by the recently added
> non-blocking code in libssh2-0.15.
> To try to diagnose the problem, I built my test program with gcc 3.2
> instead of the Sun Studio 11 compiler and I used gdb to step
> through the
> libssh2-0.15-20070605 code. The problem occurs at line 308 of
> transport.c. The recv function is returning -1 but errno is 0, which
> should be impossible.
> The problem is that the global variable errno should not be accessed
> directly when multi-threaded. We should add -D_REENTRANT to
> the Makefiles. That causes errno to be redefined in errno.h to be
> (*(___errno())), which is threadsafe.
> I made this change in my Makefiles and rebuilt the library. Now my
> application is able to use sftp in different threads.
> I'm not familiar with the intricacies of the configure script. I think
> this change should be made there, so that the configured Makefiles
> have
> the correct definition of CPPFLAGS.
> Would someone please make this change?

Will have to be someone with more knowledge then me, all the systems
I have access to always define errno as:

            extern int * __error();
            #define errno (* __error())


/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------     The Power to Serve
Fortune Not Found:
Abort, Retry, Ignore?
This email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
libssh2-devel mailing list
Received on 2007-06-08