Permissions/ownership for a per-user launch agent
I have a per-user agent that needs to be able to access the default printer for the current user. I'm having problems figuring out how to load it in the current user context from my installer postflight script. If I use "launchctl load" without sudo from Terminal, my agent loads correctly in the current user context and is able to access the user's default printer. If I load using sudo from Terminal, my agent cannot get the user's default printer. I have the following at the end of my postflight script:
chmod 755 /Library/Application\ Support/MyFolder/myd chmod 644 /Library/LaunchAgents/com.mycompany.myd.plist launchctl load -w /Library/LaunchAgents/com.mycompany.myd.plist
The problem is that my postflight script is running as root which results in the launchctl command being executed as root, leading to the problem with not being able to access the default printer. There seem to be a few options I could use to fix this issue but most of them are poorly documented. Among these are: * The ProcessType, UserName and GroupName keys in the launchd.list * The -s sessiontype option for launchctl load * This note from the launchctl man page: "Note that per-user configuration files (LaunchAgents) must be owned by the user loading them." In case it helps, here is the plist that I install into /Library/LaunchAgents: <dict> <key>Label</key> <string>com.mycompany.myd</string> <key>Debug</key> <true/> <key>ProgramArguments</key> <array> <string>/Library/Application Support/MyFolder/myd</string> <string>launchd</string> </array> <key>Sockets</key> <dict> <key>PrimaryListeningSocket</key> <dict> <key>SockServiceName</key> <string>2687</string> <key>SockNodeName</key> <string>localhost</string> <key>SockFamily</key> <string>IPv4</string> </dict> </dict> </dict> /Mick
2 dec 2013 kl. 19:12 skrev Mitchell J Laurren-Ring <lists@rynosoft.com>:
The problem is that my postflight script is running as root which results in the launchctl command being executed as root, leading to the problem with not being able to access the default printer.
This is because the installer and the user’s session aren’t in the same bootstrap context. Details here, read carefully: https://lists.macosforge.org/pipermail/launchd-dev/2011-January/000890.html The script I use is here: https://github.com/MagerValp/Scripted-Mac-Package-Creation/blob/master/scrip... -- Per Olofsson, IT-service, University of Gothenburg
participants (2)
-
Mitchell J Laurren-Ring
-
Per Olofsson