[launchd-dev] Problem with launchd starting user defined launchagent service in root user login
tclementdev at gmail.com
Thu Dec 22 02:04:04 PST 2011
On Dec 22, 2011, at 10:56 AM, Nandini Vijayashankar wrote:
> Thanks again for you reply.
> May I know is there any apple documentation related to this "-u" parameter for launchctl?
Not that I know of.
> And why does "launchctl unload /System/Library/LaunchAgents/<plistfile>" does not work from root user login?
> As per my knowledge, LaunchAgents is started in logged in user context and when the root user has logged in,
> that user should be able to execute the above command successfully
Because launchctl is designed to switch to the system context when called as root so that you can control the system daemons when calling it with the "sudo" command.
Therefore this is what launchctl does when called from the root user session which is not what you want since you actually want to talk to the root user context (and control the root user agents).
This is why you need the "-u root" option to tell launchctl that you want to talk to the root user context instead of switching to the system context.
> >>> Thomas Clement <tclementdev at gmail.com> 12/22/2011 3:04 PM >>>
> The "-u" flag only works for the root user.
> Maybe you can have a condition in your shell script and use the "-u root" option only when appropriate.
> On Dec 22, 2011, at 10:29 AM, Nandini Vijayashankar wrote:
>> Thanks a lot...
>> Its working from root user login.
>> If I use the same command from non-root user login, iam getting error.
>> I used:
>> launchctl -u <username> unload /System/Library/LaunchAgents/<plistfile>
>> Unknown user:<username>
>> I want to use a generic command from my shell script to unload the plist file which is applicable for both root and non-root user login.
>> Is it possible?
>> >>> Thomas Clement <tclementdev at gmail.com> 12/22/2011 2:40 PM >>>
>> You should try:
>> launchctl -u root unload /System/Library/LaunchAgents/<plistfile>
>> On Dec 22, 2011, at 6:00 AM, Nandini Vijayashankar wrote:
>>> I want to know how does launchd start the user defined launchagents service when a "root" user logs in to the system.
>>> Iam using Mac 10.6
>>> I have a launchdaemon and launchagent present in /System/Library/LaunchDaemons and /System/Library/LaunchAgents.
>>> When I login with a non-root user, my launchagent service is started as that logged in user.
>>> I can unload this service using "launchctl unload /System/Library/LaunchAgents/<plistfile>"
>>> If I login as root user,my launchagent service is started and working fine.But its not started as logged in user ie., root.
>>> If I try to unload through "launchctl unload /System/Library/LaunchAgents/<plistfile>" I get error:
>>> launchctl : Error unloading <id>
>>> This is because the service is not launched as root user.
>>> Above scenarios are working fine in Mac 10.5 as root and non-root user.
>>> When i see my launchagent service in Activity monitor, the parent process is the per-user launchd instance.
>>> The parent process of this launchd is system launchd with pid 1.
>>> I have tried to list the service using various commands:
>>> launchctl list
>>> launchctl bslist
>>> sudo launchctl list
>>> All these are not showing my launchagent service.Is there any special way, launchd launches launchagents service when a root user logs in Mac 10.6?
>>> How can i unload my launchagent service when the root user logs in?
>>> launchd-dev mailing list
>>> launchd-dev at lists.macosforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the launchd-dev