X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; q=dns; s= default; b=ArzBM3O0NrwE5pKHERIxbBzUlv/KwjOXa4TfIuNc0LPVsY4225DWM FyaACn27tGAzVIcyaBGLADi9nXRg+DXVq/qQaeMUctwujRQp/NdsN3F00LrbWDTr 5RAUbkifs90IisyVfpfeEwovW1RfjRkTe0v+d3RAe06PzQlCZVkqk8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; s=default; bh=AzAmnR2yagVIylAOwdWIXJ6vssM=; b=f3wRcrHVztL+hI4xK5SpwHnK1MXF uSeqfW2kxK/tIOFxSBAtnevBrariu48rnNB7nIyhVFgxvsn8jKUk1Soz3bFtYlfq efU/aZmtXnqepXRwx/yC4rbOylG7ZI8k0Z0vQsozxJDtpdzaXVUlVsefFxJWBXnF NYsWo5h16Ix3fLU= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: calimero.vinschen.de Date: Wed, 19 Feb 2014 19:46:48 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: Bug with dlopen() and fork() Message-ID: <20140219184648.GW2246@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8MWQa5Xlpje7WrDu" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) --8MWQa5Xlpje7WrDu Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > I've searched for a similar problem in the mailing lists and found > this unanswered thread from 2001: >=20 > http://cygwin.com/ml/cygwin/2001-02/msg01225.html >=20 >=20 > I'm running cygwin64. This behaviour can be checked with the following > test program: >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D > #include > #include >=20 > int (*myopen)(const char *); >=20 > main(){ > void *handle; > int ret; > handle =3D dlopen("my_lib.dll", RTLD_LAZY); > myopen =3D dlsym(handle, "mylib_open"); >=20 > if( ! fork() ){ > ret =3D myopen(""); > printf("This printf never shows, call to myopen will > block for ever\n"); > } > else{ > ret =3D myopen(""); > printf("%i\n", ret); > sleep(1); > } > } > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D >=20 > Same program runs correctly (showing the two printf's) in a Linux environ= ment. Works for me with 64 bit Cygwin. I used this as DLL: $ cat > my_lib.c <