[launchd-dev] launchd: how is it supposed to be done?

Damien Sorresso dsorresso at apple.com
Mon Jun 29 15:04:53 PDT 2009


On Jun 29, 2009, at 2:44 PM, Iceberg-Dev wrote:
> What I can do:
> --------------
>
> Create a plist file for launchd to launch a tool every time at  
> startup (even though the required plist contents are apparently  
> changing with each OS release because it's probably more funny like  
> that).

The required plist keys have not changed since 10.4. Label,  
ProgramArguments, Program. Please read launchd.plist(5) for specifics.  
Don't worry too much about how Program isn't required if  
ProgramArguments is present. Just provide them both, pretend you're  
calling execve(2) and save yourself some headaches.

> What I am trying to do:
> -----------------------
>
> I'm trying to launch a helper daemon (not an agent) on demand.
>
> Ideally, it would work this way:
>
> - Process (P) needs to talk with Daemon (D)
>
> - Daemon (D) is launched on demand by launchd based on some socket  
> or mach port magic.
>
> - (D) notifies (P) that it's ready to listen
>
> - (P) talks to (D). (P) does what it is supposed to do then.
>
> - After that (P) waits for a while and if nothing happens, it quits.
>
>
> What I have tried so far:
> -------------------------
>
> - Read the launchd.plist and launchdman pages. It just gives me  
> headaches as like most man pages it assumes you know how to do  
> something and is not didactic.

I'm sorry that the documentation is so dry, but that's a common  
feature of all technical documentation. There are some deficiencies,  
but we try to be clear as to what each key does. Which parts in  
particular were confusing?

> - Tried the sample code from the ADC Website. It does not event  
> built and the bug report I filed to suggest to get it fixed was  
> probably sent to /dev/null as I haven't heard about it since.

What's the Radar number? What sample code was this? (Did you attempt  
to fix the code yourself?)

> - Looked for sample code using google. Was not able to find a single  
> good example. There are plenty of examples showing how to write  
> equivalents of crontab, StartupItems but none for triggering a  
> daemon with sockets or a mach port. Some of them apparently try to  
> deal with file dependencies it is not clear if they are even sure  
> with this.

The lack of good Mach examples sucks, and I'm sorry that the situation  
is the way it is. But that's really all I can say about it.

> By the way:
> -----------
>
> I attended the session on launchd at WWDC and was still like Alicia  
> Silverstone in that 1995 movie after that. I must be an idiot.

There was a rather extensive Q&A session after that talk, and I made  
myself available for questions even after that. Did I talk to you at  
all?

> Questions:
> ----------
>
> - Is there an example somewhere that _works_ and covers launching a  
> daemon with launchd using sockets or mach port as dependencies?

BetterAuthorizationSample shows a job which can be launched on-demand  
whenever there is a connection to a Unix domain socket.

> - Is there a tutorial somewhere that covers this subject?
>
> - Are these mach port and socket things really working? I dare ask  
> because socket dependency was supposed to work on 10.4.0 and AFAIK,  
> it was only supported way later.


Launching jobs on-demand based on connections made to a socket has  
worked since 10.4. Mach port-based demand works on 10.5 and later; as  
of 10.5, basically the entire operating system uses this facility.
-- 
Damien Sorresso
BSD Engineering
Apple Inc.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2425 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/launchd-dev/attachments/20090629/b55cc26a/attachment.bin>


More information about the launchd-dev mailing list