bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glibc 2.2.5 connect issue


From: Andreas Jaeger
Subject: Re: glibc 2.2.5 connect issue
Date: Sat, 09 Feb 2002 19:13:47 +0100
User-agent: Gnus/5.090006 (Oort Gnus v0.06) XEmacs/21.4 (Artificial Intelligence, i386-suse-linux)

"Me" <address@hidden> writes:

> I have a simple test program which fails...
> The issue is a combination of factors...
>    a> load a shared library (dlopen, dlsym)
>    b> invoke a function in that library which creates a thread
> (pthread_create)

If you dlopen a shared lib that uses threads you should link your
application against the thread library.  Otherwise the main program is
not thread safe and this might cause the problems you see,

Andreas

>    c> have that thread attempt a connect() on a socket().
>
> The connect() will fail with -1, but will not set errno.
>
> Attached are the following three files in a .tgz format....
>
> I'm running a sorcery distribution with linux kernel version 2.4.17 or
> 2.5.3.  I have traced the code, the __libc_connect() invokes a syscall, the
> result code -115 is returned in eax, but under this set of circumstances
> errno() is not set with any value.  I have tested a couple possible errors -
> a> ewouldblock b>addressnotsupported...
> I am currently building 2.2.4 version of glibc....
>
> I have tested this using gcc 2.96(good system) and gcc 2.95.3(failing
> system) - copying the same binary to 2 systems (other running a kernel
> 2.4.7-10. 2.2.16), they both work, pretty much since the result from the int
> $0x80 syscall is correct, I'm going to point my finger at glibc.
>
> kernel 2.4.17 gcc 2.95.3 glibc 2.2.5 fails
> kernel 2.5.3 gcc 2.95.3 glibc 2.2.5 fails
> kernel 2.2.16-22 gcc 2.96 glibc 2.1.92 (redhat 7.1) succeeds
> kernel 2.4.7-10 gcc 2.96 glibc 2.2.4 (redhat 7.2) fails
>
> hmmm well guess 2.2.4 won't work anyhow.. aborted that installation....
>
> ---- Makefile ---
>
> LDFLAGS= -g # link for no debug loggings
> CFLAGS= -g
> LDLIBS=-lpthread
>
> all: loader puser puser.so
>
> test:
>  #echo 'Loader loads .so, .so makes a thread that '
>  #echo 'attempts to connect a nonblocking socket...'
>  export LD_LIBRARY_PATH=./ && ./loader
>  #echo 'program makes a thread which attempts to connect...'
>  ./puser
>
> loader:
>  gcc -g -o loader loader.c -ldl
>
> puser:    puser.o
> puser.so: puser.o
>  ld -shared $(LDFLAGS) -o $@ $< -lpthread
> puser.o:  puser.c
>
> -- end makefile ---
> -- loader.c ---
> #include <stdio.h>
> #include <errno.h>
> #include <dlfcn.h>
>
> int main( int argc, char **argv )
> {
>     void* hModule;
>     int (*nextmain)(int argc, char **argv );
>     hModule = dlopen( "puser.so", RTLD_NOW );
>     if( !hModule )
>         fprintf( stderr, "Failed to load program puser(%s)\n", dlerror() );
>     else
>     {
>         nextmain = dlsym( hModule, "main" );
>         return nextmain( argc-2, argv+2 );
>     }
>     return 0;
> }
> -- end loader.c --
> -- puser.c ---
> #include <stdio.h>
>
> #include <netinet/in.h>
> #include <sys/socket.h>
> #include <sys/time.h>
> #include <netdb.h>
> #include <errno.h>
>
> #include <sys/ioctl.h>
>
> //struct sockaddr sa={2,{0,23,127,0,0,1}};
> struct sockaddr sa={2,{0,23,255,255,255,255}};
>
> int DedicatedConnect( void )
> {
>     int Socket;
>     Socket=socket( PF_INET, SOCK_STREAM, IPPROTO_TCP );
>     if (Socket < 0)
>     {
>         printf( "Create socket failed.\n" );
>         return 0;
>     }
>     else
>     {
>         int err;
>         // optional code here... just plain doesn't work at all...
>         {
>             int t = 1;
>             ioctl( Socket, FIONBIO, &t );
>         }
>         errno = 50000;
>         if( err = connect( Socket, &sa, sizeof(sa) ) )
>         {
>             unsigned long dwError;
>             dwError = errno;
>             // this is the expected error... but connect never sets errno...
>             if( dwError != EINPROGRESS )
>             {
>                 printf( "errno will be whatever was before connect...\n" );
>                 printf( "Connect FAIL: socket:%d connect:%d errno:%d\n",
> Socket, err, dwError );
>                 return 0;
>             }
>             else
>                 printf( "Expected result - success - connection in
> progress\n" );
>         }
>         else
>             printf( "Success? %d", err );
>     }
>     return 1;
> }
>
>
> void *thread( void *junk )
> {
>     if( !DedicatedConnect() )
>     {
>         printf( "failed to open\n" );
>         return 0;
>     }
>     while( 1 )
>     {
>         usleep(100000);
>     }
>     return NULL;
> }
>
>
> int main( char argc, char** argv )
> {
>     pthread_t junk;
>     pthread_create( &junk, NULL, thread, NULL );
>     printf( "Press return to exit\n" );
>     fgetc(stdin);
>     return 0;
> }
> -- end puser.c ---
>
> PLEASE respond if there's a fix...
>

-- 
 Andreas Jaeger
  SuSE Labs address@hidden
   private address@hidden
    http://www.suse.de/~aj



reply via email to

[Prev in Thread] Current Thread [Next in Thread]