6e6e405db2413b91d5cb93685e7299f46d206088
[platform/upstream/coreutils.git] / tests / mv / leak-fd
1 #!/bin/sh
2 # Exercise mv's file-descriptor-leak bug, reported against coreutils-5.2.1
3 # and fixed (properly) on 2004-10-21.
4
5 # This test is relatively expensive, and might well evoke a
6 # framework-failure on systems with a smaller command-line length
7 # limit so don't run it by default.
8 . $srcdir/../expensive
9
10 if test "$VERBOSE" = yes; then
11   set -x
12   mv --version
13 fi
14
15 . $srcdir/setup
16 . $srcdir/../envvar-check
17 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
18
19 pwd=`pwd`
20 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
21 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
22 trap '(exit $?); exit $?' 1 2 13 15
23
24 if test -z "$other_partition_tmpdir"; then
25   (exit 77); exit 77
26 fi
27 t0="$t0 $other_partition_tmpdir"
28
29 framework_failure=0
30 mkdir -p $tmp || framework_failure=1
31 cd $tmp || framework_failure=1
32
33 b="0 1 2 3 4 5 6 7 8 9
34 a b c d e f g h i j k l m n o p q r s t u v w x y z
35 _A _B _C _D _E _F _G _H _I _J _K _L _M _N _O _P _Q _R _S _T _U _V _W _X _Y _Z"
36
37 for i in `echo $b`; do
38   echo $i
39   for j in $b; do
40     echo $i$j
41   done
42 done > .dirs
43 mkdir `cat .dirs` || framework_failure=1
44 sed 's,$,/f,' .dirs | xargs touch
45
46 last_file=`tail -n1 .dirs`/f
47 test -f $last_file || framework_failure=1
48
49 if test $framework_failure = 1; then
50   echo "$0: failure in testing framework" 1>&2
51   (exit 1); exit 1
52 fi
53
54 fail=0
55
56 mv * $other_partition_tmpdir || fail=1
57 test -f $last_file/f && fail=1
58 rm .dirs
59
60 ls -A > ../out || fail=1
61 test -s ../out && fail=1
62
63 (exit $fail); exit $fail