Re: [launchd-dev] OnDemand USB Software
Hi Quinn, sorry for the delay, somehow I missed your answer (probably because the mailing list digest only arrived two days ago, 9 days after you sent the answer ;-). Am 27.03.2008 um 16:12 schrieb Quinn <eskimo1@apple.com>:
At 23:23 +0100 17/3/08, Mike Fischer wrote:
So far, looking at tn2083 and the man pages, I don't see any way to have a depency on USB or IOKit in general. Am I missing something here?
No, you're not missing something. This is a much-requested feature that we're tracking as <rdar://problem/4551362>.
OK. If we go ahead with this project I'll probably file a (duplicate) bug to raise the priority.
If there is no direct support would it make sense to have a very small, lightweight daemon always running that registers for IOKit IOServiceAddMatchingNotification notifications and creates a semaphore file that can be used to trigger the launch of the real daemon for example?
That's a fine way to do it. I probably wouldn't use a semaphore file, because it persists in the file system. However, there are numerous other options available to you. If I was doing this, I'd probably have your main daemon register a UNIX domain socket and have your lightweight daemon connect to that socket to trigger a launch.
OK. The semaphore file was just the first trigger I could think of that would work with launchd. The UNIX domain socket is probably a better idea. If I understand this correctly I would not be using the socket for actual communication, just for triggering the launch of the "server", i.e. the real (on demand) daemon? So I'd include something like this in the real daemon's launchd.plist: <key>Sockets</key> <dict> <key>Listeners</key> <dict> <key>SockNodeName</key> <string>/tmp/MYSOCKETNAME</string> </dict> </dict> Would I need to add the SockFamily or SockProtocol keys and if so what would be the correct values for a UNIX domain socket? Anything else I'd need to add? In the real daemon I'd do a socket(2), bind(2), accept(2) (the listen (2) is already done by launchd I gather)? Or do I need this at all? And in the USB-Watcher daemon I'd do a socket(2), connect(2), which would trigger the launch of the real daemon right? BTW: The launchd.plist(5) man page contains references to a launch(3) man page (10.5.2, Xcode 3.0 as well as 10.4.11, Xcode 2.4.1). Unfortunatly the launch(3) man page does not seem to exist. Filed as <rdar://5830171>. I saw /usr/include/launch.h and the SampleD sample code but these don't really explain what is going on and how to properly check-in with launchd. Any hints on where to get more information?
BTW: This would be mainly for Leopard, although Tiger would be interesting too.
This approach would work just fine on 10.4.x (x >= 6 if you use UNIX domain sockets).
Good to know. Now I need to discuss these options with my customer and see if we can do this without completely changing their existing cross platform code. Thanks! Your answer is very much appreciated. Mike -- Mike Fischer Softwareentwicklung, EDV-Beratung Schulung, Vertrieb Web: <http://homepage.mac.com/mike_fischer/index.html> Note: I read this list in digest mode! Send me a private copy for faster responses.
At 22:02 +0100 29/3/08, Mike Fischer wrote:
BTW: The launchd.plist(5) man page contains references to a launch(3) man page (10.5.2, Xcode 3.0 as well as 10.4.11, Xcode 2.4.1). Unfortunatly the launch(3) man page does not seem to exist. Filed as <rdar://5830171>. I saw /usr/include/launch.h and the SampleD sample code but these don't really explain what is going on and how to properly check-in with launchd. Any hints on where to get more information?
Thanks for all those bug reports. We appreciate 'em. IMHO the best example of how to use launchd with a UNIX domain socket is: <http://developer.apple.com/samplecode/BetterAuthorizationSample/index.html>
If I understand this correctly I would not be using the socket for actual communication, just for triggering the launch of the "server", i.e. the real (on demand) daemon?
That's the idea, yes.
Would I need to add the SockFamily or SockProtocol keys and if so what would be the correct values for a UNIX domain socket? Anything else I'd need to add?
o SockFamily == Unix o SockPathMode is typically 438 (0666, rw-rw-rw-) -- This may not strictly be necessary in your case because the code that's connecting is privileged. o SockNodeName == ??? -- It's generally best to put this in a privileged location (/var/run/) rather than in /tmp.
In the real daemon I'd do a socket(2), bind(2), accept(2) (the listen(2) is already done by launchd I gather)? Or do I need this at all?
In a launchd daemon you don't need to do the socket, or the bind, or the listen. You just get a file descriptor for the socket from launchd (using LAUNCH_KEY_CHECKIN) and accept connections from that. S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
participants (2)
-
Mike Fischer
-
Quinn