Re: question about mach ports and fork
Re: question about mach ports and fork
- Subject: Re: question about mach ports and fork
- From: Jim Magee <email@hidden>
- Date: Wed, 21 Jan 2004 14:43:59 -0800
On Jan 21, 2004, at 3:37 PM, Nathan T. Hjelm wrote:
I have tried to open a new connection to iokit with the child process
by
calling IOCreateMasterPort again but I get the same result as when I
didn't. The problem must lie in the IOService which looks like it keeps
trak of the master port used to open it. It would be a really simple
fix
if i could rely on the programmer to call usb_open on a device after
the
fork call (i think. i know there are a number of ports invalidated
that I
don't really know about).
After fork()ing the memory image is stale (i.e. contain names for Mach
ports that the child doesn't actually have). One could argue that all
these frameworks should install atfork() handlers and clean up this
state. The problem is that it is not really possible to determine the
order those handlers have to be called in in order to assure all
dependencies are met (the spec says they are called in the same order
that they are registered, but the order required to "re-initialize" the
frameworks may be quite different than the order to initialize them the
first time). So, we haven't gone that route (except for the basic Un*x
libraries).
Instead, you MUST exec() after fork() in any process that is using any
Mac OS X-specific frameworks. You can re-exec the same executable -
and pass a parameter to indicate that it has already fork()'ed and
doesn't need to again. If you do this, you will re-initialize
correctly.
--Jim
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.