Re: launchd and UNIX Domain Sockets Example
Re: launchd and UNIX Domain Sockets Example
- Subject: Re: launchd and UNIX Domain Sockets Example
- From: Quinn <email@hidden>
- Date: Tue, 23 Oct 2007 21:43:44 +0100
At 14:17 -0400 23/10/07, Steve Sisak wrote:
What isn't immediately obvious is how to set up the the plist to
register a unix daemon -- I'm guessing that I just set SockPathName
instead of SockServiceName, but would like a quick sanity check and
to know if there are other options I need to set.
That's pretty much it. The only other gotcha is that you want to set
SockPathMode to an appropriate value, otherwise you'll find that only
root can connect to your socket.
I don't have a plist handy, but I have some code that /generates/
such plists from a template, and I've pasted the template in below.
As far as handling pre-10.4, your only real option is to use a
startup item. Here's the general idea:
o If you're running on 10.4 or later, install as a launchd daemon and
you're done. Don't support taking a 10.4 setup back to 10.3.
o If you're running on 10.3, install as a startup item. This exec's
your core daemon tool with an argument that indicates that it's
running as a startup item rather than a launchd daemon.
o If the startup item detects that it's been started on 10.4, have it
munge itself into a launchd daemon. Remove the startup item and
install the launchd plist. Use launchctl to start the launchd
daemon. Again, the launchd plist tells the core daemon that it's
running via launchd.
o In the core daemon, if you're running as a startup item, daemonise
yourself and then create your listening socket by hand. Otherwise,
try to check in with launchd.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
static const char * kPlistTemplate =
// The standard plist header.
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"
\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
"<plist version=\"1.0\">\n"
"<dict>\n"
// We install the job disabled, then enable it as the last step.
" <key>Disabled</key>\n"
" <true/>\n"
// Use the bundle identifier as the job label.
" <key>Label</key>\n"
" <string>%s</string>\n"
// Use launch on demand.
" <key>OnDemand</key>\n"
" <true/>\n"
// There are no program arguments, other that the path to the
helper tool itself.
//
// IMPORTANT
// kBASToolPathFormat embeds a %s
" <key>ProgramArguments</key>\n"
" <array>\n"
" <string>" kBASToolPathFormat "</string>\n"
" </array>\n"
// The tool is required to check in with launchd.
" <key>ServiceIPC</key>\n"
" <true/>\n"
// This specifies the UNIX domain socket used to launch the tool, including
// the permissions on the socket (438 is 0666).
//
// IMPORTANT
// kBASSocketPathFormat embeds a %s
" <key>Sockets</key>\n"
" <dict>\n"
" <key>" kLaunchDSocketDictKey "</key>\n"
" <dict>\n"
" <key>SockFamily</key>\n"
" <string>Unix</string>\n"
" <key>SockPathMode</key>\n"
" <integer>438</integer>\n"
" <key>SockPathName</key>\n"
" <string>" kBASSocketPathFormat "</string>\n"
" <key>SockType</key>\n"
" <string>Stream</string>\n"
" </dict>\n"
" </dict>\n"
"</dict>\n"
"</plist>\n"
;
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden