leak-fd.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. # Copyright (C) 2004-2018 Free Software Foundation, Inc.
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. # limit so don't run it by default.
  16. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  17. print_ver_ mv
  18. skip_if_root_
  19. cleanup_() { rm -rf "$other_partition_tmpdir"; }
  20. . "$abs_srcdir/tests/other-fs-tmpdir"
  21. # This test is relatively expensive, and might well evoke a
  22. # framework-failure on systems with a smaller command-line length
  23. expensive_
  24. b="0 1 2 3 4 5 6 7 8 9
  25. 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
  26. _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"
  27. for i in $(echo $b); do
  28. echo $i
  29. for j in $b; do
  30. echo $i$j
  31. done
  32. done > .dirs
  33. mkdir $(cat .dirs) || framework_failure_
  34. sed 's,$,/f,' .dirs | xargs touch
  35. last_file=$(tail -n1 .dirs)/f
  36. test -f $last_file || framework_failure_
  37. mv * "$other_partition_tmpdir" || fail=1
  38. test -f $last_file/f && fail=1
  39. rm .dirs
  40. out=$(ls -A) || fail=1
  41. test -z "$out" || fail=1
  42. Exit $fail