Setting environment variable for xpc service:

I set the following global environment variables to launchd derives services :

Code Block
sudo launchctl setenv CA_DEBUG_TRANSACTIONS 1
sudo launchctl setenv CA_ASSERT_MAIN_THREAD_TRANSACTIONS 1


And indeed I saw that reflected on SecurityAgent (of type launchAgent) :

Code Block
sudo ps eww 3194
PID TT STAT TIME COMMAND
3194 ?? Ss 0:00.19 /System/Library/Frameworks/Security.framework/Versions/A/MachServices/SecurityAgent.bundle/Contents/MacOS/SecurityAgent
LaunchInstanceID=00000000-0000-0000-0000-00000001873A XPC_SERVICE_NAME=com.apple.security.agent.login
CA_DEBUG_TRANSACTIONS=1 CA_ASSERT_MAIN_THREAD_TRANSACTIONS=1 PATH=/usr/bin:/bin:/usr/sbin:/sbin XPC_FLAGS=19 LOGNAME=_securityagent USER=_securityagent HOME=/var/db/securityagent SHELL=/usr/bin/false TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n00000bh00002w/T/


But unfortunately, his helper XPC Service doesn’t get them :

Code Block
sudo ps eww 3195
PID TT STAT TIME COMMAND
3195 ?? Ss 0:00.53 /System/Library/Frameworks/Security.framework/Versions/A/MachServices/SecurityAgent.bundle/Contents/XPCServices/SecurityAgentHelper.xpc/Contents/MacOS/SecurityAgentHelper XPC_SERVICE_NAME=com.apple.SecurityAgentHelper PATH=/usr/bin:/bin:/usr/sbin:/sbin HOME=/var/db/securityagent TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n00000bh00002w/T/ XPC_FLAGS=19 LOGNAME=_securityagent USER=_securityagent SHELL=/usr/bin/false

Any idea how set it in the helper too even if it’s an xpc service and not an agent, since they both runs by launchd:

Code Block
92 3194 1 0 11:42AM ?? 0:00.19 /System/Library/Frameworks/Security.framework/Versions/A/MachServices/SecurityAgent.bundle/Contents/MacOS/SecurityAgent
92 3195 1 0 11:42AM ?? 0:00.53 /System/Library/Frameworks/Security.framework/Versions/A/MachServices/SecurityAgent.bundle/Contents/XPCServices/SecurityAgentHelper.xpc/Contents/MacOS/SecurityAgentHelper

Setting environment variable for xpc service

Can you rebuild the XPC Service? If so, by far the easiest way to achive this goal is via the EnvironmentVariables property of the XPC Services’s property list. See the xpcservice.plist man page for details.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Setting environment variable for xpc service:
 
 
Q