PATH environment variable incorrectly set from launchd configuration file in 10.10

Originator:matthew.brett
Number:rdar://18945659 Date Originated:10/11/2014
Status:Open Resolved:
Product:OSX Product Version:10.10 / 14A389
Classification: Reproducible:Always
 
Summary:
In past versions of OSX, setting PATH was effective from the EnvironmentVariables section of a launchd plist configuration script.

In 10.10, setting PATH from EnvironmentVariables appears to result in the path being set twice, so that there are two "PATH" environment variables (as shown for example by a ruby script - see below). 

This results in the PATH EnvironmentVariable setting being ignored by - for example - Python scripts (see below).

Steps to Reproduce:
To run example launchd configuration script and review output environment variables:

cp envvars.plist py_env_out /tmp
cd /tmp
rm -rf /tmp/*env_vars && launchctl load envvars.plist && sleep 1 && launchctl unload envvars.plist && cat /tmp/*env_vars

The envvars.plist script uses EnvironmentVariables to set the PATH to:

PATH : /a/funny/path:/bin:/usr/bin:/usr/sbin:/sbin

The script then runs a trivial Python file to print out the environment variables.

Expected Results:
On OSX 10.9 the output of the commands above is:

PATH : /a/funny/path:/bin:/usr/bin:/usr/sbin:/sbin
VERSIONER_PYTHON_PREFER_32_BIT : no
ANOTHER_VAR : some value
VERSIONER_PYTHON_VERSION : 2.6

This is what I was expecting. 

If I edit envvars.plist to run a ruby file to print out the environment variables:

       <key>Program</key>
        <string>/tmp/rb_env_out</string>

Then I get this output, also expected:

PATH : /a/funny/path:/bin:/usr/bin:/usr/sbin:/sbin
ANOTHER_VAR : some value


Actual Results:
On OSX 10.10, the output is:

VERSIONER_PYTHON_PREFER_32_BIT : no
VERSIONER_PYTHON_VERSION : 2.7
XPC_SERVICE_NAME : edu.berkeley.envvars
XPC_FLAGS : 0x0
PATH : /usr/bin:/bin:/usr/sbin:/sbin
ANOTHER_VAR : some value

Note that ANOTHER_VAR is correctly set, but the PATH is not correctly set.

Running the ruby program to output the environment variables (see above), I get this:

PATH : /usr/bin:/bin:/usr/sbin:/sbin
ANOTHER_VAR : some value
PATH : /a/funny/path:/bin:/usr/bin:/usr/sbin:/sbin
XPC_SERVICE_NAME : edu.berkeley.envvars
XPC_FLAGS : 0x0

Note there are two "PATH" variables here, one that appears to be the default, and the other from EnvironmentVariables.

If I switch to a bash program to output the environment variables:

       <key>Program</key>
        <string>/tmp/sh_env_out</string>

Then the PATH is echoed as expected.

bash-4.3# cat envvars.plist 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>edu.berkeley.envvars</string>

        <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
            <string>/a/funny/path:/bin:/usr/bin:/usr/sbin:/sbin</string>
            <key>ANOTHER_VAR</key>
            <string>some value</string>
        </dict>
        <key>Program</key>
        <string>/tmp/py_env_out</string>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>
bash-4.3# cat py_env_out 
#!/usr/bin/env python
import os

with open('/tmp/py_env_vars', 'wt') as fobj:
    for key, value in os.environ.items():
        fobj.write('{0} : {1}\n'.format(key, value))
bash-4.3# cat rb_env_out 
#!/usr/bin/env ruby
File.open('/tmp/rb_env_vars', 'w') { |file|
    ENV.each do |k,v|
       file.write("#{k} : #{v}\n")
    end
}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!