My app needs to write files at restricted places on the filesystem, namely : /Library/Application Support.
Following the guidelines, and based on Apple sample code (SMJobBless, BetterAuthorizationSample, EvenBetterAuthorizationSample), I wrote a second, tiny application whose sole purpose is to install those files.
Everything is up and running for this part, I get the helper tool installed using SMJobBless(), after requesting authorization.
At first, I didn't get the helper tool running at all. This was solved by adding the correct keys and values in the helper launchd plist (namely RunAtLoad, and KeepAlive), that is documented in the launchd.plist (5) man page.
The second problem was that after exiting, I couldn't get the helper tool to be run a second time (even with those keys in the plist). I implemented the solution provided here (http://atnan.com/blog/2012/02/29/modern-privileged-helper-tools-using-smjobbless-plus-xpc/) to be able to wake my helper tool on demand, which works.
Now here is finally my problem :
No matter what keys and values I put in the launchd plist, launchd keeps restarting the helper process, which isn't killed or terminated in any abnormal way. The helper tool just exists upon receiving a particuliar kind of message I send to it from the main application.
I don't want the helper tool to be running forever, doing nothing but waiting (even when the main application isn't running). I want a truly 'On Demand' helper, that I can wake up and shutdown as needed.
So my question(s) is(are) :
- Why would launchd restart my helper tool every time it exit (success, or failure doesn't change the deal) ?
- How can I have a truly On Demand helper tool.
Some precisions :
I observe a similar behavior when running Apple sample code (or the one in the link), the helper tool process keeps around forever, no way is provided to tell it to exit.
I use Boost interprocess message queues to communicate from the main app to the helper (don't think it matters, but who knows)
I run OS X 10.11 and Xcode 7.0.1.
Thank you for any help !
Vince.