On Mon, 29 Oct 2007 19:47:03 +0100, "Quinn" <eskimo1@apple.com> said:
At 14:58 -0400 29/10/07, Jeremy Reichman wrote:
So now, with Leopard, LaunchAgents in /Library/LaunchAgents will run at login for each user, as the user [...], and without having to restart the computer between each user login session?
Yes. The only significant gotcha that I can think of relates to installing and upgrading. Except in the simple case (where you have one user logged in and your installer/upgrader is running in that user's context), you run into problems with the install/upgrade process. There's no built in way for you to tell all per-user launchd's on the system that a new property list has been installed (or that an old one has been upgraded). Thus, you can get into situations where one user is running version X of your agent and another is running version X+1. Or one user doesn't have the agent installed and another does. There's no really good way around this right now (although there are plenty of hackish ways).
Just for the record, we're tracking this as <rdar://problem/5476420>.
Okay, good to know. I'm not certain I will run into this situation without having a logout or reboot close by ... and I assume a logout for all users or a system reboot will resolve the situation.
as the user (by default)
The "(by default)" indicates some confusion about how agents work. An agent is always launched by a per-user launchd, and that per-user launchd is always running with its EUID and RUID set to that of the user on whose behalf it's working. Thus, there's no "by default" about it. An agent will always run as that user and there's no way around that (other than by doing something silly like making your agent setuid root). The UserName and GroupName properties in an agent's plist are ignored (as they were on 10.4.x).
I've rolled all of this info into a new Technote 2083 "Daemons and Agents" that scheduled to be published in the next couple of weeks. Watch the skies! (actually, <http://developer.apple.com> :-)
I'm looking forward to it! I hope it lays out things a little more clearly for sys admins, because I know quite a few who've given up on launchd. The "by default" confusion on my part is simply that I know it is possible to put it in the plist but I'd never personally tried to set it to some other value in a LaunchAgent. So, I was covering my bases there, even though it didn't make sense to me for a LaunchAgent to try to switch to another user's context. It's good to know that the attempt will be ignored. I'd been banging my head against the LaunchAgent wall enough in Tiger, just trying to get them to work as I expected from the man page. I'm glad to see it's worth trying again. -- Jeremy