mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-22 13:00:06 +00:00
40212ce0c9
* io/ftwtest-sh: Add test for case of symlink to nonexisting file given as start file. * io/ftw.c (ftw_startup): Use correct name in check for symlink without existing target. Patch by Jim Meyering.
208 lines
9.4 KiB
Bash
208 lines
9.4 KiB
Bash
#! /bin/sh
|
|
|
|
# The common objpfx, used to find libraries and the dynamic loader.
|
|
objpfx=$1
|
|
|
|
# We expect one parameter which is the test program. This must understand
|
|
# a number options:
|
|
# --phys use the FTW_PHYS flag
|
|
# --chdir use the FTW_CHDIR and print the current directory
|
|
# in the callback
|
|
# --depth use the FTW_DEPTH flag
|
|
# --early-exit print file@2 item only and return non-zero from the
|
|
# callback when it is seen
|
|
testprogram=$2
|
|
|
|
# We cannot test this as root.
|
|
if test `id | sed "s/uid=\([0-9]*\).*/\1/"` = 0; then
|
|
exit 0
|
|
fi
|
|
|
|
# Since we use `sort' we must make sure to use the same locale everywhere.
|
|
LC_ALL=C
|
|
export LC_ALL
|
|
LANG=C
|
|
export LANG
|
|
|
|
# First create our scenario:
|
|
tmp=`echo ${TMPDIR:-/tmp} | sed 's|\(.\)/*$|\1|'`
|
|
tmpdir=$tmp/ftwtest.d
|
|
|
|
[ -f ${objpfx}elf/ld.so ] && ldso=${objpfx}elf/ld.so
|
|
|
|
trap 'chmod -fR a+x $tmpdir; rm -fr $tmpdir $testout' 1 2 3 15
|
|
|
|
if test -d $tmpdir; then
|
|
chmod -fR a+x $tmpdir
|
|
rm -fr $tmpdir
|
|
fi
|
|
mkdir $tmpdir
|
|
mkdir $tmpdir/foo
|
|
mkdir $tmpdir/bar
|
|
echo > $tmpdir/baz
|
|
mkdir $tmpdir/foo/lvl1
|
|
echo > $tmpdir/foo/lvl1/file@1
|
|
mkdir $tmpdir/foo/lvl1/lvl2
|
|
echo > $tmpdir/foo/lvl1/lvl2/file@2
|
|
mkdir $tmpdir/foo/lvl1/lvl2/lvl3
|
|
echo > $tmpdir/foo/lvl1/lvl2/lvl3/file@3
|
|
ln -s $tmpdir $tmpdir/foo/lvl1/lvl2/lvl3/link@3
|
|
ln -s $tmpdir/foo/lvl1/lvl2 $tmpdir/foo/lvl1/lvl2/link@2
|
|
ln -s $tmpdir/foo/lvl1/lvl2/lvl3/lvl4 $tmpdir/foo/lvl1/link@1
|
|
echo > $tmpdir/bar/xo
|
|
chmod a-x,a+r $tmpdir/bar
|
|
|
|
testout=${TMPDIR:-/tmp}/ftwtest.out
|
|
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram $tmpdir |
|
|
sort > $testout
|
|
|
|
cat <<EOF | cmp $testout - || exit 1
|
|
base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
|
|
base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
|
|
base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
|
|
base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
|
|
EOF
|
|
rm $testout
|
|
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram --depth $tmpdir |
|
|
sort > $testout
|
|
|
|
cat <<EOF | cmp $testout - || exit 1
|
|
base = "$tmp/", file = "ftwtest.d", flag = FTW_DP, level = 0
|
|
base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_DP, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_DP, level = 1
|
|
base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
|
|
base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_DP, level = 2
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_DP, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_DP, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
|
|
EOF
|
|
rm $testout
|
|
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram --phys $tmpdir |
|
|
sort > $testout
|
|
|
|
cat <<EOF | cmp $testout - || exit 1
|
|
base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
|
|
base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
|
|
base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
|
|
base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SL, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "link@2", flag = FTW_SL, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "link@3", flag = FTW_SL, level = 5
|
|
EOF
|
|
rm $testout
|
|
|
|
# For the next test everything must be readable.
|
|
chmod -fR a+x $tmpdir
|
|
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir $tmpdir |
|
|
sort > $testout
|
|
|
|
# perhaps $tmp involves some symlinks...
|
|
tmpreal=`cd $tmp; /bin/pwd 2>/dev/null || /usr/bin/pwd`
|
|
|
|
cat <<EOF | cmp $testout - || exit 1
|
|
base = "$tmp/", file = "ftwtest.d", flag = FTW_D, cwd = $tmpreal, level = 0
|
|
base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
|
|
base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
|
|
EOF
|
|
rm $testout
|
|
|
|
curwd=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
|
|
cd "$tmp"
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir ftwtest.d |
|
|
sort > $testout
|
|
cd "$curwd"
|
|
|
|
cat <<EOF | diff -u $testout - || exit 1
|
|
base = "", file = "ftwtest.d", flag = FTW_D, cwd = $tmpreal, level = 0
|
|
base = "ftwtest.d/", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "ftwtest.d/", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "ftwtest.d/", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "ftwtest.d/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
|
|
base = "ftwtest.d/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
|
|
base = "ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
|
|
base = "ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
|
|
base = "ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
|
|
EOF
|
|
rm $testout
|
|
|
|
curwd=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
|
|
cd "$tmp"
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir ftwtest.d/. |
|
|
sort > $testout
|
|
cd "$curwd"
|
|
|
|
cat <<EOF | diff -u $testout - || exit 1
|
|
base = "ftwtest.d/", file = ".", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 0
|
|
base = "ftwtest.d/./", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "ftwtest.d/./", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "ftwtest.d/./", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
|
|
base = "ftwtest.d/./bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
|
|
base = "ftwtest.d/./foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
|
|
base = "ftwtest.d/./foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "ftwtest.d/./foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "ftwtest.d/./foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
|
|
base = "ftwtest.d/./foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
|
|
base = "ftwtest.d/./foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
|
|
base = "ftwtest.d/./foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
|
|
EOF
|
|
rm $testout
|
|
|
|
curwd=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
|
|
cd "$tmp"
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir ftwtest.d/foo/lvl1/link@1 |
|
|
sort > $testout
|
|
cd "$curwd"
|
|
|
|
cat <<EOF | diff -u $testout - || exit 1
|
|
base = "ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 0
|
|
EOF
|
|
rm $testout
|
|
|
|
LD_LIBRARY_PATH=$objpfx $ldso $testprogram --early-exit $tmpdir |
|
|
sort > $testout
|
|
|
|
cat <<EOF | cmp $testout - || exit 1
|
|
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
|
|
succeeded
|
|
EOF
|
|
rm $testout
|
|
|
|
rm -fr $tmpdir
|
|
|
|
exit 0
|