From owner-freebsd-current Fri Dec 4 13:34:34 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA23347 for freebsd-current-outgoing; Fri, 4 Dec 1998 13:34:34 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from smtp04.primenet.com (smtp04.primenet.com [206.165.6.134]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA23338 for ; Fri, 4 Dec 1998 13:34:31 -0800 (PST) (envelope-from tlambert@usr01.primenet.com) Received: (from daemon@localhost) by smtp04.primenet.com (8.8.8/8.8.8) id OAA19545; Fri, 4 Dec 1998 14:34:01 -0700 (MST) Received: from usr01.primenet.com(206.165.6.201) via SMTP by smtp04.primenet.com, id smtpd019465; Fri Dec 4 14:33:59 1998 Received: (from tlambert@localhost) by usr01.primenet.com (8.8.5/8.8.5) id OAA06102; Fri, 4 Dec 1998 14:33:45 -0700 (MST) From: Terry Lambert Message-Id: <199812042133.OAA06102@usr01.primenet.com> Subject: Re: Thread fd locking and fork() To: info@highwind.com (HighWind Software Information) Date: Fri, 4 Dec 1998 21:33:45 +0000 (GMT) Cc: current@FreeBSD.ORG In-Reply-To: <199812031522.KAA28193@highwind.com> from "HighWind Software Information" at Dec 3, 98 10:22:31 am X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Here is the problem: > > 1. You have a program that starts a few threads, one of these threads > blocks in "accept()" waiting for a new connection on a file descriptor. > > 2. In another thread, you want to start a child program. After the > fork(), but before exec(), you close() all the file descriptors you > don't want the child to touch. > > 3. The child hangs in close() forever. > > Why? > > At fork(), you get a copy of all the fd's. Problem is, many of them have > their file descriptors locked. > > --- > > Is there any solution to this? Perhaps the fork() code should unlock > all the descriptors. > > Does this makes sense? > > Opening a PR now. % man fcntl FCNTL(2) FreeBSD System Calls Manual FCNTL(2) NAME fcntl - file control [ ... ] F_SETFD Set the close-on-exec flag associated with fd to the low order bit of arg (0 or 1 as above). Then don't explicitly call close after the exec, since the fork() wrapper in libc_r will Do The Right Thing(tm). Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message