Issue with LaunchAgents on Multiple users logged in
Hi, 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, - In my postflight i use the 'users' command to get as to how many users have logged in and launch my app in that Users context . Sample code # Launch Menulet for all the logged in Users for userName in `/usr/bin/users` do echo "Loading Menulet for $userName" su -l $userName -c "launchctl load -S Aqua /Library/LaunchAgents/com.myname.menulet.plist" done Now in a situation where i have opened the Terminal and logged in root, the /usr/bin/users would now show as 2 users logged in and i would try to launch my app in the roots context as well. Hence i am getting 2 Menulets with the same User. How can i solve this problem? Please help ... thanks in advance ~Arjun
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
participants (2)
-
Arjun SM
-
Quinn