MacOS – launchd keeps restarting the binary in /Library/PrivilegedHelperTools

launchdmacosplist

I am looking to install a privileged helper tool using SMJobBless.
My plist only contains the MachServices key and RunAtLoad key. The RunAtLoad is set to true as I want to be launched automatically after install.

Now, the problem is that once the helper tool is installed and launched and it completes its job successfully – it gets relaunched and this keeps happening again and again.

Original launchd Job Ticket

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
<plist version="1.0">  
<key>Label</key>  
<string>com.ak.SMJobBlessHelper</string>  
<key>MachServices</key>  
<dict>  
<key>com.ak.SMJobBlessHelper.mach</key>  
<true/>  
</dict>  
<key>ProgramArguments</key>  
<array>  
<string>/Library/PrivilegedHelperTools/com.ak.SMJobBlessHelper</string>  
</array>  
<key>RunAtLoad</key>  
<true/>  
</plist>

I have tried various things to stop it from launching again but in vain:

  1. Tried to add KeepAlive to false in the plist.
  2. Tried to add KeepAlive as a dictionary with the key SuccessfulExit to false.
  3. Tried to make my app sleep for occult times before quitting like sleeping for 5 minutes, 10 minutes etc. but it still gets launched again.

I have basically run out of ideas, I want it to launch only when I ask and not automatically and that too again and again.

Please help. Thank you very much.


OS: Mac OS X 10.8.4 12E55
Xcode: 4.6.2 (4H1003)

Best Answer

The launchd job ticket in the question is malformed; the root object must be a dict:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   ...
</dict>
</plist>

Assuming this is a copy and paste error, how quickly does your com.ak.SMJobBlessHelper complete?

Some launchd configurations require the process remain running for a minimum of 30 seconds – else launchd will consider the process as crashed and automatically relaunch it.

Does your com.ak.SMJobBlessHelper conform to the requirements set out in the launchd documentation?