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). 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. - 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. - 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. 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. Questions: ---------- - Is there an example somewhere that _works_ and covers launching a daemon with launchd using sockets or mach port as dependencies? - 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.
At 23:44 +0200 29/6/09, Iceberg-Dev wrote:
- Is there an example somewhere that _works_ and covers launching a daemon with launchd using sockets or mach port as dependencies?
BetterAuthorizationSample is your friend. <http://developer.apple.com/samplecode/BetterAuthorizationSample/index.html>
- Is there a tutorial somewhere that covers this subject?
You might find the following interesting. <http://developer.apple.com/MacOsX/launchd.html> Also, BAS has lots of comments and documentation. And DaveZ's Google TechTalk is definitely worth a viewing. <http://video.google.com/videoplay?docid=1781045834610400422>
- 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.
launchd daemon launch-on-demand using Mach ports requires 10.5. It definitely works on 10.5; the system wouldn't boot otherwise. launchd daemon launch-on-demand using TCP sockets works an advertised on 10.4 and later. launchd daemon launch-on-demand using UNIX sockets works an advertised on 10.4 and later, but it's not particularly useful without SockPathMode which is available on all platforms starting with 10.4.6. S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
On Jun 29, 2009, at 11:52 PM, Quinn wrote:
At 23:44 +0200 29/6/09, Iceberg-Dev wrote:
- Is there an example somewhere that _works_ and covers launching a daemon with launchd using sockets or mach port as dependencies?
BetterAuthorizationSample is your friend.
<http://developer.apple.com/samplecode/BetterAuthorizationSample/ index.html>
Not sure. Looked at it and it probably won't work in my case as: - I don't want to ask the user a password every time. This is apparently cover by the sample code in one specific case. I need to look at this more deeply. - I may have 2 different processes talking to the privileged tool. - The sample doesn't seem secure with the helper tool being embedded in the application bundle. There is a potential root escalation privilege issue here. - I didn't see a LaunchDaemon plist file. Basically the issue I see (and have) is that if you want to launch a tool on every startup, it's a very simple plist to write (and right permissions to set). If you want to depend on socket or mach port, it's apparently a ton of code you have to write or understand. There is a huge gap between these 2 cases and the ladder is missing some steps.
- Is there a tutorial somewhere that covers this subject?
[...] Also, BAS has lots of comments and documentation. And DaveZ's Google TechTalk is definitely worth a viewing.
<http://video.google.com/videoplay?docid=1781045834610400422>
Looks like it covers the same topics as old WWDC sessions.
At 1:06 +0200 30/6/09, Iceberg-Dev wrote:
BetterAuthorizationSample is your friend.
<http://developer.apple.com/samplecode/BetterAuthorizationSample/index.html>
Not sure. Looked at it and it probably won't work in my case as:
Ah, you misunderstand me. Sorry for not being clearer. The overall goal of BAS is to demonstrate how to do the 'self install' thing, and you're not interested in the that, so it's obviously not a good match for your particular product. However, if you run the sample and then look at the final state of the system, you'll see how a launch-on-demand launchd daemon is meant to be set up. That is, you can look at the property list it installs, the helper tool it installs, and the source to that helper tool, and thence see how you should set up your daemon. Specifically, run the sample and look at the following: o The plist file installed in "/Library/LaunchDaemons/<bundleID>.plist". o The helper tool installed in "/Library/PrivilegedHelperTools/<bundleID>". o The code used by the helper tool to check in with launchd. Specifically, the CheckInWithLaunchd routine in "BetterAuthorizationSampleLib.c". <http://developer.apple.com/samplecode/BetterAuthorizationSample/listing1.html> S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
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.
On Jun 30, 2009, at 12:04 AM, Damien Sorresso wrote:
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?
I guess the #1 problem is that the Example section (ofd launchd.plist (5)) lacks examples. I understand that you can't put a lot of examples but right now (I'm looking on 10.4.10 so forgive me if it's not totally up to date), there is only one simple example.
- 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?)
#6908216 SampleD Didn't try fixing it since I'm in learning mode and would probably do more damages than anything else.
- 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?
The topic about socket and mach port was not really covered in the session. So it didn't look to be a good topic for Q&A.
On Jun 29, 2009, at 3:31 PM, Iceberg-Dev wrote:
I guess the #1 problem is that the Example section (ofd launchd.plist (5)) lacks examples. I understand that you can't put a lot of examples but right now (I'm looking on 10.4.10 so forgive me if it's not totally up to date), there is only one simple example.
The examples you're seeking are a little more involved. The plist keys are the easy part. It's the code in the client and server (especially with Mach) that gets tricky and is poorly-documented.
#6908216
SampleD
Didn't try fixing it since I'm in learning mode and would probably do more damages than anything else.
There's no explanation of *what* is failing in the project build. What error did you get? Is a compiler error? Linker error? Missing SDK? Don't assume that we'll be able to reproduce your failure; everyone has different systems. You should add this information to your bug report. Please see http://developer.apple.com/BugReporter/bugbestpractices.html for bug reporting guidelines. For what it's worth, SampleD builds without issue on 10.6 under the 10.5 SDK. It was originally written for the 10.4 SDK, so the fact that you're having problems is odd.
- 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?
The topic about socket and mach port was not really covered in the session. So it didn't look to be a good topic for Q&A.
Sockets and Mach ports are principally how launchd's on-demand functionality was implemented. If that wasn't communicated adequately by the session, I'm sorry. But it would've been a completely appropriate question to ask. -- Damien Sorresso BSD Engineering Apple Inc.
On Jun 30, 2009, at 12:47 AM, Damien Sorresso wrote:
On Jun 29, 2009, at 3:31 PM, Iceberg-Dev wrote:
I guess the #1 problem is that the Example section (ofd launchd.plist(5)) lacks examples. I understand that you can't put a lot of examples but right now (I'm looking on 10.4.10 so forgive me if it's not totally up to date), there is only one simple example.
The examples you're seeking are a little more involved. The plist keys are the easy part. It's the code in the client and server (especially with Mach) that gets tricky and is poorly-documented.
#6908216
SampleD
Didn't try fixing it since I'm in learning mode and would probably do more damages than anything else.
There's no explanation of *what* is failing in the project build. What error did you get? Is a compiler error? Linker error? Missing SDK? Don't assume that we'll be able to reproduce your failure; everyone has different systems. You should add this information to your bug report.
Will do. You just have to follow the ReadMe instructions to fail. Selene:~ stephane$ cd /Volumes/Work/SampleD/ Selene:/Volumes/Work/SampleD stephane$ cp SampleD /tmp Selene:/Volumes/Work/SampleD stephane$ sudo launchctl load ./ com.apple.dts.SampleD.plist Password: launchctl: opendir() failed to open the directory nothing found to load On Mac OS X 10.4.10.
Please see
http://developer.apple.com/BugReporter/bugbestpractices.html
for bug reporting guidelines.
For what it's worth, SampleD builds without issue on 10.6 under the 10.5 SDK. It was originally written for the 10.4 SDK, so the fact that you're having problems is odd.
participants (3)
-
Damien Sorresso
-
Iceberg-Dev
-
Quinn