descriptor-vs-rename.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. # Demonstrate that tail -f works when renaming the tailed files.
  3. # Between coreutils 7.5 and 8.23 inclusive, 'tail -f a' would
  4. # stop tracking additions to b after 'mv a b'.
  5. # Copyright (C) 2015-2018 Free Software Foundation, Inc.
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  17. print_ver_ tail
  18. check_tail_output()
  19. {
  20. local delay="$1"
  21. grep "$tail_re" out ||
  22. { sleep $delay; return 1; }
  23. }
  24. # Terminate any background tail process
  25. cleanup_() { kill $pid 2>/dev/null && wait $pid; }
  26. # Speedup the non inotify case
  27. fastpoll='-s.1 --max-unchanged-stats=1'
  28. for mode in '' '---disable-inotify'; do
  29. rm -f a out
  30. touch a || framework_failure_
  31. tail $mode $fastpoll -f a > out 2>&1 & pid=$!
  32. # Wait up to 12.7s for tail to start.
  33. echo x > a
  34. tail_re='^x$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; }
  35. mv a b || framework_failure_
  36. echo y >> b
  37. # Wait up to 12.7s for "y" to appear in the output:
  38. tail_re='^y$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; }
  39. cleanup_
  40. done
  41. Exit $fail