Mac OS X command-line gotcha: path_helper

Ran into an issue where my terminals were coming up **really** slowly.
It ended up being a line in the script /usr/libexec/path_helper.

It turns out Apple has set up a whole process for modifying users’ PATHs by adding text files in /etc/paths.d, which is really a good idea, since install/uninstall scripts can just add/remove text files instead of mucking around with users’ login scripts.
For some reason it was taking about 30 seconds to execute this line of bash:


[[ /Users/t_ellir/bin/Darwin:/Users/t_ellir/bin/Darwin-i386:/Users/t_ellir/bin/noarch:/Users/t_ellir/bin/osx-rae:/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/lib:/Developer/Tools:/usr/X11/bin:/Applications/ccollab_client:/Users/t_ellir/mudbox/dev/bin/macos:/System/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin:/System/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin = *(*:)/usr/local/bin*(:*) ]]

But it had no problem zipping through other directories, e.g.:


[[ /Users/t_ellir/bin/Darwin:/Users/t_ellir/bin/Darwin-i386:/Users/t_ellir/bin/noarch:/Users/t_ellir/bin/osx-rae:/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/lib:/Developer/Tools:/usr/X11/bin:/Applications/ccollab_client:/Users/t_ellir/mudbox/dev/bin/macos:/System/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin:/System/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin = *(*:)/usr/sbin*(:*) ]]

so it has something specifically to do with it being /usr/local/bin.
I didn’t have that directory so I created it, but that didn’t help.
I finally kludged around it by removing the directory and then patching the script to test for the existence of the directory before trying the test:

--- path_helper 2008-11-04 11:54:18.000000000 -0500
+++ /usr/libexec/path_helper    2008-11-04 11:54:47.000000000 -0500
@@ -15,6 +15,7 @@
        for f in "$DIR" "$DIR".d/* ; do
          if [ -f "$f" ]; then
                for p in $(< "$f") ; do
+                       [ ! -d "${p}" ] && continue
                        [[ "$NEWPATH" = *(*:)${p}*(:*) ]] && continue
                        [ ! -z "$NEWPATH" ] && SEP=":"
                        NEWPATH="${NEWPATH}${SEP}${p}"

Props to
kilala.nl
for having a blog post about this.



2 Responses to “Mac OS X command-line gotcha: path_helper”

  1. Music Says:

    thanks for the coding its very useful.

  2. MacPress Says:

    never understand the code that why i using os x

Leave a Reply