Page MenuHomeFreeBSD

Avoid realpath(3) if not needed.
ClosedPublic

Authored by bdrewery on Nov 14 2018, 6:24 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 20, 1:48 PM
Unknown Object (File)
Wed, Apr 17, 10:34 AM
Unknown Object (File)
Wed, Apr 10, 9:18 PM
Unknown Object (File)
Thu, Mar 28, 8:35 PM
Unknown Object (File)
Mar 14 2024, 11:27 AM
Unknown Object (File)
Mar 2 2024, 9:01 PM
Unknown Object (File)
Jan 24 2024, 5:42 AM
Unknown Object (File)
Jan 12 2024, 12:20 AM
Subscribers

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
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 20807
Build 20201: arc lint + arc unit

Event Timeline

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

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.