[launchd-dev] Issue with LaunchAgents on Multiple users logged in

Quinn eskimo1 at apple.com
Wed May 6 01:56:09 PDT 2009


At 12:12 +0530 6/5/09, Arjun SM wrote:
>I have written a small menulet application and is running as a 
>LaunchAgent. The problem that i am facing is while installing my app 
>and in situation when multiple Users are logged in,

Yeah, this is one of the still-open holes in the launchd story.  It's 
very hard to upgrade an agent in a multiple GUI users setup.  Your 
current approach is never going to work.  The problem is that 
switching the UID (as done by "su") does not, by itself, put you in 
another the other user's GUI execution context.  At a minimum you 
also have to switch bootstrap namespace.  However, even that's not 
guaranteed to be sufficient.  In short, there is no supported way to 
get into a particular GUI context other than by being launched there.

My recommendation solution is that you detect this case and require a 
restart on install.  Fast user switching is not the mostly commonly 
used feature, so the majority of your users won't care.  And an edge 
case like this is not without precedent: try restarting your system 
in the same situation and you'll see some pretty ugly dialogs from 
Apple code )-:

Another reasonable solution is to enlist the active help of your 
agents.  Presumably your agents are connected to a single daemon. 
When you want to update the agents, just overwrite them on disk and 
then have your daemon notify the agents that they need to quit. 
launchd will restart the agents with your new code.  There are two 
drawbacks to this approach:

o It typically only works if you planned it advance.  If you already 
have agents running in the field, you may run into trouble.

o It only solves the update problem; it helps not a jot for the first 
install problem.

We know that this story is less than ideal.  We have a bug requesting 
a better solution <rdar://problem/5476420> but that's not going to 
get addressed in the near future.

S+E
-- 
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware


More information about the launchd-dev mailing list