Here is a fix that I suggest for 0.9.31.
It is in folder linuxthreads.old, but I don't know if it also applies to the 
"new" version.

--- a/libpthread/linuxthreads.old/errno.c       2010-04-02 11:34:27.000000000 
-0400
+++ b/libpthread/linuxthreads.old/errno.c       2010-05-11 09:44:16.589502638 
-0400
@@ -22,6 +22,7 @@
 #include "internals.h"
 #include <stdio.h>
 
+libpthread_hidden_proto(__errno_location)
 int *
 __errno_location (void)
 {
@@ -29,6 +30,7 @@
   return THREAD_GETMEM (self, p_errnop);
 }
 
+libpthread_hidden_proto(__h_errno_location)
 int *
 __h_errno_location (void)
 {

The problem is shown when running the program in attachment.
A thread cannot read the right value of errno, but the main can.
The output of the program is:

thread: Failed to connect (-1 errno=0): Operation now in progress
main: Failed to connect (-1 errno=115): Operation now in progress

Regards,

Jean-Denis Boyer, Eng.
Media5 Corporation - Mediatrix, M5T, Media5Boss
4229 Garlock Street, Sherbrooke (Québec), J1L 2C8, CANADA
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <errno.h>

void MakeConnection(char *pszComment)
{
    int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (s == -1)
    {
        perror("socket");
    }
    else
    {
        int flags = fcntl(s, F_GETFL);
        if (fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
        {
            perror("fcntl");
        }
        else
        {
            struct sockaddr_in addr = { AF_INET, htons(389), { 
htonl(0x0A150001) } };
            int res = connect(s, (struct sockaddr *)&addr, sizeof(addr));
            if (res = -1)
            {
                char buf[256];
                sprintf(buf, "%s: Failed to connect (%d errno=%d)", pszComment, 
res, errno);
                perror(buf);
            }
            else
            {
                printf("Success!\n");
            }
        }
        close(s);
    }
}

void * ThreadEntry(void *arg)
{
    MakeConnection("thread");
    return 0;
}

int main()
{
    pthread_t tt;
    pthread_create(&tt, NULL, ThreadEntry, NULL);
    pthread_join(tt, NULL);
    MakeConnection("main");
}

_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to