Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: open fails in daemon



On Tuesday, July 22, 2003, at 2:19 AM, Steve Cox wrote:
Thanks so much for your help, Jim. My daemon is in fact calling daemon(),
and I don't call fork().

Well, daemon() does a fork() for you. So, it still could be a fork()-related issue. Does your code not call daemon() when launched as a startupitem? Also, make sure you always compare pre-bound vs. pre-bound. Often, it's just the difference between pre-bound and not that can trigger these fork() issues (init routines are all called up front in pre-bound applications and on first use of a framework otherwise).

I think your second guess is correct - my daemon
is being started in a login context, instead of in the startup context.
According to Apple's 'Kernel Programming' book, there are 3 ways to launch
a program in the startup context
1. put it in a startup script so that it launches at boot time (I've done
this and it works fine)
2. start it using ssh (so my installer will need to run this -- but I
can't get 'ssh localhost <app>' to succeed)

This is out-of-date (the document is being updated for Panther final). Since Jaguar, ssh sessions each get their own bootstrap "login" context.

3. login as the console user.
Are there any other ways to launch my program in the startup context
(while a user is logged in)?

In Panther, there should be a StartupItemContext utility that will launch an application, give you a shell, run the debugger, etc... in the startup item context even though it is initially run from a login context. It uses privileged calls to accomplish this migration (so you must be root to run it). You could use the same calls, but they aren't guaranteed to work across releases (in fact, they are different for Jaguar vs. Panther). So, until Panther, it's probably better to stick with startup scripts (and/or attaching with gdb if you can).

You also mention the possibility of using standard BSD/UNIX facilities
instead of relying on OS X. But is there any BSD/UNIX interface for
launching an OS X Carbon application?

I believe you can always just exec() the executable inside the bundle (if it's Mach-O) instead of using open() on the bundle itself.

--Jim
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: open fails in daemon (From: Jim Magee <email@hidden>)
 >Re: open fails in daemon (From: "Steve Cox" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.