Re: cocoa-dev digest, Vol 2 #1291 - 12 msgs
Re: cocoa-dev digest, Vol 2 #1291 - 12 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #1291 - 12 msgs
- From: Ryan McGann <email@hidden>
- Date: Mon, 23 Sep 2002 23:19:43 -0700
On Monday, September 23, 2002, at 10:00 PM, Terence Goggin wrote:
Everything was working fine until today when I created a proper
installer
for the system and did the install. Suddenly, it was clear that the
daemons
(launched as StartupItems now instead of just via sudo in the terminal)
were not communicating with the main app.
Does your startup item call daemon()?
daemon() calls fork(), and fork() doesn't copy the Mach ports
associated with the parent process. In order to circumvent this, don't
call daemon() in the same process that vends the distributed object.
First, call daemon and then relaunch yourself. This makes sure that no
mach ports are opened when daemon() is called, and therefore the mach
ports your DO "vends" are still valid.
In your startup item, you need to do the following in your main():
if ( strcmp( "start", argv[ 1 ] ) == 0 )
{
// Relaunch ourself as a daemon, instead of calling daemon from
inside the main executable. We pass ourself a different argument so we
know if we're being relaunched or launched for the first time.
int err = daemon( TRUE, TRUE );
if ( err != 0 )
{
// You've got real troubles here.
}
else
{
argv[ 1 ] = "run";
execve( "/Library/StartupItems/<Path to your StartupItem", &argv[0],
environ);
}
}
else
{
// We're being realunched. Continue execution as normal...
}
I have an application that communicates with a startup item using
distributed objects, and it seems to work fine. I have a sample project
I can send you if you want.
Ryan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.