• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Launch agent runs as root immediately after install
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launch agent runs as root immediately after install


  • Subject: Re: Launch agent runs as root immediately after install
  • From: Greg Neagle <email@hidden>
  • Date: Fri, 19 Mar 2010 09:21:45 -0700

Yes, but it's fragile, and will probably break in future releases of the OS. With each release of OS X, Apple makes it harder and harder for a root process to operate in a user's context.
This works only for the currently logged in user; any users logged in but switched out via fast user switching don't get to play.


Step 1: find a process running as the current user and get its PID:

(Current username in $USER)

PSOUT=`ps auxwww | grep Finder | grep $USER | grep -v grep`
PID=`echo $PSOUT | cut -d" " -f2`

Step 2: use a very complicated call to launchctl to start the agent in the user's context:

/bin/launchctl bsexec $PID /usr/bin/sudo -u $USER /bin/bash -c 'unset SUDO_COMMAND ; /bin/launchctl start com.myorg.mylaunchagent'

I suppose you could figure out all the currently logged in users and repeat this process for each one to handle the FUS users as well.

If it were me, I'd just require a logout (if I didn't care about supporting Fast User Switched users), or a restart (if it was important that everyone got the new functionality).

-Greg

On Mar 19, 2010, at 2:58 AM, Chris Adamson wrote:

We're installing a LaunchAgent that we want to get up and running immediately, so in a post-install script, we call "launchctl load / Library/LaunchAgents/path.to.our.agent.plist".

I've noticed that this runs the agent as root, whereas the agent will run as the user on subsequent logins.

Is there a way to get the agent running as the user who's performing the install, rather than root?

Thanks in advance.

--Chris

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Installer-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Launch agent runs as root immediately after install
      • From: Xochitl Lunde <email@hidden>
References: 
 >Launch agent runs as root immediately after install (From: Chris Adamson <email@hidden>)

  • Prev by Date: Re: Launch agent runs as root immediately after install
  • Next by Date: Re: Launch agent runs as root immediately after install
  • Previous by thread: Re: Launch agent runs as root immediately after install
  • Next by thread: Re: Launch agent runs as root immediately after install
  • Index(es):
    • Date
    • Thread