path_helper does not read paths.d in a reliable order

Originator:mattieruth
Number:rdar://39564397 Date Originated:4/19/2018
Status:Open Resolved:
Product:macOS + SDK Product Version:10.13
Classification: Reproducible:Yes
 
Area:
Something not on this list

Summary:
the path_helper tool used to set the PATH does not read the /etc/paths.d directory in a reliable way. It used to do so alphabetically, but this seems to no longer be the case.

Steps to Reproduce:
Copy the attached paths.d files into /private/etc/paths.d and run /usr/libexec/path_helper

Expected Results:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/some/path/4:/some/path/3:/some/path/2:/some/path/1

Actual Results:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/some/path/1:/some/path/4:/some/path/2:/some/path/3

Version/Build:
Mac OS X : 10.13.4


-------------------------------------------------

Post filing comment:

I have found someone who has provided a patched version of path_helper to resolve this issue -- https://gist.github.com/nohillside/a4da0e1bb00135de163a7d4059b69fd5

That said, I deploy software to people that adds its path via the paths.d mechanism and would like to avoid enforcing that they use a patched version of path_helper, so that patch doesn't work as-is for me.

Thank you!

Comments

Better test case and patched version

See https://github.com/dankegel/path_helper for a clean fix with a simple test case.

By daniel.r.kegel at June 15, 2018, 3:30 p.m. (reply...)

Looks like I can't attach the four files I attached to the original bug here. They were simply:

filename: 598-paths-for-me-1
content: /some/path/1

filename: 597-paths-for-me-2
content: /some/path/2

filename: 596-paths-for-me-3
content: /some/path/3

filename: 595-paths-for-me-4
content: /some/path/4

By mattieruth at June 15, 2018, 1:21 p.m. (reply...)

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!