STINNER Victor <[email protected]> added the comment:
Alexey Izbyshev:
> Would it make sense to use os.confstr('CS_PATH') instead of a hardcoded path,
> or is identical behavior on all POSIX platforms preferred to that?
I didn't know this variable. man confstr says:
_CS_PATH: A value for the PATH variable which indicates where all the
POSIX.2 standard utilities can be found.
On my Fedora 29, it only returns '/usr/bin':
$ python3
>>> import os; os.confstr("CS_PATH")
'/usr/bin'
On Fedora 29, /bin is a symlink to /usr/bin:
$ ls -ld /bin
lrwxrwxrwx. 1 root root 7 13 juil. 2018 /bin -> usr/bin/
So it makes sense to omit /bin from the default search path :-)
On Debian Sid where /bin is still a distinct directory than /usr/bin, CS_PATH
is equal to "/bin:/usr/bin".
On Fedora, using confstr() would have the advantage of avoiding one useless
syscall stat("/bin/program") in addition to stat("/usr/bin/program") in
shutil.which() if the program doesn't exist... It's really a micro optimization
which has no impact on the correctness, for the specific case of Fedora.
About the correctness, FreeBSD has a different value:
>>> os.confstr("CS_PATH")
'/usr/bin:/bin:/usr/sbin:/sbin'
Not only it also includes /usr/sbin and /sbin, but /usr/bin has the preference
over /bin (posixpath of Python 3 checks /bin before /usr/bin). I'm not sure if
the different order has an impact about correctness. I only found two programs
which are in /bin and /usr/bin, but the programs in /usr/bin are symbolic links
to a program with the same name in /bin :-)
vstinner@freebsd$ python3
Python 3.6.6 (default, Nov 20 2018, 01:57:10)
>>> import os
>>> usr=os.listdir("/usr/bin")
>>> bin=os.listdir("/bin")
>>> set(usr) & set(bin)
{'pkill', 'pgrep'}
vstinner@freebsd$ file /usr/bin/pkill
/usr/bin/pkill: symbolic link to ../../bin/pkill
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35755>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com