Skip to content

Commit c232b51

Browse files
spacefroggMichael Raitza
authored and
Michael Raitza
committed
Remove absolute pathnames to binaries and rely on PATH
Fixes issues with distributions that use non-standard binary paths (e.g., in isolated build environments). Scripts rely on PATH for other programs, anyway. Use /usr/bin/env to find the pwd binary avoiding the shell built-in.
1 parent b08b5ef commit c232b51

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

do

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ usage() {
2424
}
2525

2626
mydir=$(dirname "$0")
27-
cd "$(/bin/pwd)" && cd "$mydir" || die "can't find self in dir: $mydir"
27+
cd "$(env pwd)" && cd "$mydir" || die "can't find self in dir: $mydir"
2828

2929
args=
3030
while [ "$1" != "${1#-}" ]; do

minimal/do

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ qdirname() (
5454
)
5555

5656
_dirsplit "$0"
57-
REDO=$(cd "$(pwd -P)" &&
57+
REDO=$(cd "$(env pwd -P)" &&
5858
cd "${_dirsplit_dir:-.}" &&
5959
echo "$PWD/$_dirsplit_base")
6060
export REDO
@@ -89,7 +89,7 @@ if [ -z "$DO_BUILT" -a "$_cmd" != "redo-whichdo" ]; then
8989
if [ "$#" -eq 0 ] && [ "$_cmd" = "do" -o "$_cmd" = "redo" ]; then
9090
set all # only toplevel redo has a default target
9191
fi
92-
export DO_STARTDIR="$(pwd -P)"
92+
export DO_STARTDIR="$(env pwd -P)"
9393
# If starting /bin/pwd != $PWD, this will fix it.
9494
# That can happen when $PWD contains symlinks that the shell is
9595
# trying helpfully (but unsuccessfully) to hide from the user.
@@ -228,7 +228,7 @@ _realpath()
228228
#echo "Trying: $PWD--$path" >&2
229229
if cd -P "$path" 2>/dev/null; then
230230
# success
231-
pwd=$(pwd -P)
231+
pwd=$(env pwd -P)
232232
#echo " chdir ok: $pwd--$rest" >&2
233233
np=$(_normpath "${pwd%/}/$rest" "$relto")
234234
if [ -n "$isabs" ]; then

minimal/do.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ mkdir y
136136
ln -s . y/x
137137
check "/usr/__does_not/b" _realpath "/usr/__does_not/a/../b" "$x"
138138
check "foo" _realpath "y/x/x/x/x/x/../foo" "$PWD"
139-
check "$(/bin/pwd)/foo" _realpath "$PWD/y/x/x/x/x/x/../foo" "$PWD"
139+
check "$(env pwd)/foo" _realpath "$PWD/y/x/x/x/x/x/../foo" "$PWD"
140140
check "foo/blam" _realpath "y/x/x/x/x/x/../foo/spam/../blam" "$PWD"
141-
check "$(/bin/pwd)/foo/blam" _realpath "$PWD/y/x/x/../foo/spam/../blam" "$PWD"
141+
check "$(env pwd)/foo/blam" _realpath "$PWD/y/x/x/../foo/spam/../blam" "$PWD"
142142

143143

144144
SECTION _find_dofile

t/105-sympath/all.do

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ for iter in 10 20; do
1414
cd y/x/x/x/x/x
1515
IFS=$(printf '\n')
1616
redo-ifchange static x/x/x/static $PWD/static \
17-
$(/bin/pwd)/static /etc/passwd
17+
$(env pwd)/static /etc/passwd
1818
redo-ifchange $PWD/../static 2>/dev/null && exit 35
1919
redo-ifchange 1.dyn x/x/x/2.dyn $PWD/3.dyn \
20-
$PWD/../4.dyn $(/bin/pwd)/5.dyn
20+
$PWD/../4.dyn $(env pwd)/5.dyn
2121
)
2222
[ -e y/1.dyn ] || exit $((iter + 1))
2323
[ -e y/2.dyn ] || exit $((iter + 2))

t/all.do

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ fi
1010

1111
# builds 1xx*/all to test for basic/dangerous functionality.
1212
# We don't want to run more advanced tests if the basics don't work.
13-
/bin/ls 1[0-9][0-9]*/all.do |
13+
ls 1[0-9][0-9]*/all.do |
1414
sed 's/\.do$//' |
1515
xargs redo
1616
110-compile/hello >&2
1717

1818
# builds most of the rest in parallel
19-
/bin/ls [2-9][0-9][0-9]*/all.do |
19+
ls [2-9][0-9][0-9]*/all.do |
2020
sed 's/\.do$//' |
2121
xargs redo
2222

@@ -25,7 +25,7 @@ xargs redo
2525
# are checking for unnecessary extra rebuilds of some targets, which
2626
# might happen after flush-cache.
2727
# FIXME: a better solution might be to make flush-cache less destructive!
28-
/bin/ls [s][0-9][0-9]*/all.do |
28+
ls [s][0-9][0-9]*/all.do |
2929
sed 's/\.do$//' | {
3030
while read d; do
3131
redo "$d"

t/clean.do

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/bin/ls [0-9s][0-9][0-9]*/clean.do |
1+
ls [0-9s][0-9][0-9]*/clean.do |
22
sed 's/\.do$//' |
33
xargs redo
44

t/shelltest.od

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ rm -f shlink ../shlink
526526
ln -s . shlink
527527
(quiet_stderr cd -L shlink/shlink/shlink/../shlink) || fail 120
528528
(quiet_stderr cd -P shlink/shlink/shlink/../shlink) && fail 121
529-
x1=$(cd shlink && basename "$(pwd -P)")
530-
x2=$(cd shlink && basename "$(pwd -L)")
529+
x1=$(cd shlink && basename "$(env pwd -P)")
530+
x2=$(cd shlink && basename "$(env pwd -L)")
531531
[ "$x1" = "t" ] || fail 122
532532
[ "$x2" = "shlink" ] || fail 123
533533

0 commit comments

Comments
 (0)