[launchd-dev] Agent terminating & Fast User Switching

Peter Alshuth palshuth at gmail.com
Tue Jun 24 10:55:44 PDT 2008


Hi all,

I have an agent running for each user session that gets launched when  
the user logs in and  will be terminated on a logout.

In order to have the background agent running even if the user quits  
it I use the key to KeepAlive (I check the reason for the quit event  
and return 0 or 1).

Everything works fine when only one user is logged in and out. But  
when I log out from a fast user switching it will be restarted:

He agent fist received the quit event and will terminate by calling  
exit(1) at the very end. Unfortunately, it will be relaunched during  
the user logout and the process will immediately receive  SIGTERM  
signal that I also response to.

<plist version="1.0">
<dict>
	<key>KeepAlive</key>
         <dict>
                 <key>SuccessfulExit</key>
                 <true/>
         </dict>
         <key>Label</key>
         <string>com.mycompany.myAgent</string>
         <key>OnDemand</key>
         <false/>
         <key>ProgramArguments</key>
         <array>
                 <string>/usr/local/MyStuff/MyAgent.app/Contents/MacOS/ 
MyAgent</string>
         </array>
         <key>RunAtLoad</key>
         <true/>
</dict>
</plist>


Is there anything I am missing or doing wrong?

Thanks for any help,
Peter




More information about the launchd-dev mailing list