Date: Fri, 4 Dec 1998 21:33:45 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: info@highwind.com (HighWind Software Information) Cc: current@FreeBSD.ORG Subject: Re: Thread fd locking and fork() Message-ID: <199812042133.OAA06102@usr01.primenet.com> In-Reply-To: <199812031522.KAA28193@highwind.com> from "HighWind Software Information" at Dec 3, 98 10:22:31 am
next in thread | previous in thread | raw e-mail | index | archive | help
> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812042133.OAA06102>