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: Gutjahr, Troy <Troy.Gutjahr_at_tellabs.com>
Date: Thu, 7 Jun 2007 14:15:29 -0500

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 CPPFLAGS in
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?

Thanks.

-- Troy Gutjahr
============================================================
The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader
of this message is not the intended recipient, or an employee
or agent responsible for delivering this message to the
intended recipient, you are hereby notified that any reproduction,
dissemination or distribution of this communication is strictly
prohibited. If you have received this communication in error,
please notify us immediately by replying to the message and
deleting it from your computer. Thank you. Tellabs
============================================================

-------------------------------------------------------------------------
This SF.net 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.
http://sourceforge.net/powerbar/db2/
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-06-07