On 26 Oct 2010, at 03:55, Jerry Krinock wrote:
On 2010 Oct 25, at 18:01, eveningnick eveningnick wrote:
Also there's a /usr/include/launch.h file, which provides some kind of API, but i've no idea how to use it, and i am not sure if it gives any means to load/start/stop/unload agents. Maybe i could use it somehow?
Anyone know what he's talking about?
The routines in <launch.h> provide necessary services for launchd jobs (daemons and agents). Specifically, a launchd job uses this API to check in with launchd. See SampleD for an example of this. <http://developer.apple.com/library/mac/#samplecode/SampleD/> If you need to manipulate the launchd state, you should use Service Management (if it's available and does what you want) or simply fork/exec launchctl. And yes, it is both sad and a chore )-:
how can i determine, if my agent is running or not, from my Cocoa application? and how could i determine if it's registered (loaded, in terms of launchctl) or not? Calling [NSTask launchProcess:@"launchctl list | grep com.mycompany.myagent"] and then parsing the returned string seems wrong to me :/. Is it really the only choice?
That's the only choice that I know of. Again, this is quite sad.
The approach I usually use here (for example, this is what BAS shows) is to have my launchd job provide a service, and then try to connect to that service. If the connection works, the job must be installed properly. If the connection fails, some corrective action is necessary. S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware