Page MenuHomeFreeBSD

Avoid realpath(3) if not needed.
ClosedPublic

Authored by bdrewery on Nov 14 2018, 6:24 PM.

Details

Summary

realpath(3) can be quite heavy, especially if using NFS-mounted root.

Test Plan
/usr/local/bin # ls -al hm
lrwxr-xr-x  1 root  wheel  7 Nov 14 10:15 hm@ -> clang70
/usr/local/bin # ./hm
/usr/local/bin/clang70
clang-7: error: no input files
/usr/local/bin # hm
/usr/local/bin/clang70
clang-7: error: no input files
/usr/local/bin # clang++70
/usr/local/bin/clang++70
clang-7: error: no input files

Diff Detail

Repository
rP FreeBSD ports repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

bdrewery created this revision.Nov 14 2018, 6:24 PM

I don't understand how this can work is the working directory isn't /usr/local/bin.

~/git/poudriere3 # cat /usr/local/bin/clang70
#!/bin/sh
# $FreeBSD: head/devel/llvm70/files/llvm-wrapper.sh.in 466018 2018-03-31 03:28:42Z tobik $

LLVM_PREFIX="/usr/local/llvm70"
LLVM_SUFFIX="70"

tool=$0
[ -L "$tool" ] && tool=$(/bin/realpath $tool)
echo $tool
tool=${tool##*/}
tool="${LLVM_PREFIX}/bin/${tool%${LLVM_SUFFIX}}"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}${LLVM_PREFIX}/lib" \
    "${tool}" "${@}"

~/git/poudriere3 # ls -al hm
lrwxr-xr-x  1 root  wheel  22 Nov 14 14:04 hm@ -> /usr/local/bin/clang70
~/git/poudriere3 # ./hm
/usr/local/bin/clang70
clang-7: error: no input files

~/git/poudriere3 # ls -al /usr/local/bin/hm
lrwxr-xr-x  1 root  wheel  7 Nov 14 14:04 /usr/local/bin/hm@ -> clang70
~/git/poudriere3 # /usr/local/bin/hm
/usr/local/bin/clang70
clang-7: error: no input files

~/git/poudriere3 # which hm
/usr/local/bin/hm
~/git/poudriere3 # hm
/usr/local/bin/clang70
clang-7: error: no input files

If I remove the -L line then it breaks as expected:

~/git/poudriere3 # hm
/usr/local/bin/hm
/usr/local/bin/hm: /usr/local/llvm70/bin/hm: not found
brooks accepted this revision.Nov 15 2018, 12:18 AM

Oh right, of course that works. Things called from $PATH are run with a full path in $0.

This revision is now accepted and ready to land.Nov 15 2018, 12:18 AM
This revision was automatically updated to reflect the committed changes.