X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Mon, 5 Nov 2007 11:21:47 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: cygwin stable and cvs snapshot - fork() bug Message-ID: <20071105102147.GI31224@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <4721DFCC DOT 8070100 AT cygwin DOT com> <20071029083512 DOT GA4224 AT calimero DOT vinschen DOT de> <4725D656 DOT 5090303 AT cygwin DOT com> <20071101095835 DOT GG31224 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071101095835.GG31224@calimero.vinschen.de> User-Agent: Mutt/1.5.16 (2007-06-09) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 On Nov 1 10:58, Corinna Vinschen wrote: > On Oct 31 14:26, Lev Bishop wrote: > > $ cat lev.c && gcc -o lev lev.c -Wall -Wextra && CYGWIN=server ./lev > > #include > > #include > > #include > > > > int main(void) > > { > > int shmid; > > if ((shmid = shmget(IPC_PRIVATE, 100,IPC_CREAT | 0600 )) < 0 || > > !shmat(shmid, NULL, 0) || > > shmctl(shmid, IPC_RMID, NULL) < 0) > > puts("problems with shm!"); > > fork(); > > } > > lev.c: In function `main': > > lev.c:13: warning: control reaches end of non-void function > > 3 [main] lev 1924 c:\Documents and > > Settings\Lev\Desktop\mpd-0.13.0\lev.exe: *** fatal error - > > MapViewOfFileEx (0x3E0000), Win32 error 6. Terminating. > > 124 [main] lev 5076 fork: child 1924 - died waiting for dll > > loading, errno 11 > > Thanks for the testcase. I'm surprised that nobody experienced this > problem before. Sorta holiday here, so I'll look into it next week. Ouch, ouch, ouch. shmctl(IPC_RMID) closed the handle to the shared memory, but neglected to remove the actual mappings as well as the bookkeeping structure. The result is that after a fork the child thinks there are still mappings which have to be duplicated into its own memory. But the handle has already been closed in the parent, so the MapViewOfFile call fails with "invalid handle". Unfortunately not many applications use shmctl(IPC_RMID) before creating a child process since usually the shared memory is meant to be... well, shared. That's why this didn't crop up more often, obviously. I've applied a fix to CVS. Thanks again for the testcase, Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/