Bug with dlopen() and fork()
Corinna Vinschen
corinna-cygwin@cygwin.com
Wed Feb 19 18:49:00 GMT 2014
On Feb 19 14:38, Jaime Fabregas Fernandez wrote:
> Library references loaded by a process using dlopen() and dlsym() are
> no more valid in child processes after running a fork(). Calls from
> child process will never return.
>
> I've searched for a similar problem in the mailing lists and found
> this unanswered thread from 2001:
>
> http://cygwin.com/ml/cygwin/2001-02/msg01225.html
>
>
> I'm running cygwin64. This behaviour can be checked with the following
> test program:
>
> ========================================================
> #include <stdio.h>
> #include <dlfcn.h>
>
> int (*myopen)(const char *);
>
> main(){
> void *handle;
> int ret;
> handle = dlopen("my_lib.dll", RTLD_LAZY);
> myopen = dlsym(handle, "mylib_open");
>
> if( ! fork() ){
> ret = myopen("");
> printf("This printf never shows, call to myopen will
> block for ever\n");
> }
> else{
> ret = myopen("");
> printf("%i\n", ret);
> sleep(1);
> }
> }
> ========================================================
>
> Same program runs correctly (showing the two printf's) in a Linux environment.
Works for me with 64 bit Cygwin. I used this as DLL:
$ cat > my_lib.c <<EOF
int
mylib_open (const char *foo)
{
return 1;
}
$ gcc -shared -o my_lib.dll my_lib.c
$ gcc -g -o my_tst my_tst.c <- That's your above testcase
$ uname -a
CYGWIN_NT-6.3 vmbert8164 1.7.28(0.271/5/3) 2014-02-04 16:01 x86_64 Cygwin
$ ./my_tst
1
This printf never shows, call to myopen will block for ever
$
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140219/60f31e74/attachment.sig>
More information about the Cygwin
mailing list