follow-stdin.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. # Test tail -f -
  3. # Copyright (C) 2009-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ tail
  16. #################
  17. # tail -f - would fail with the initial inotify implementation
  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. echo line > in || framework_failure_
  29. echo line > exp || framework_failure_
  30. for mode in '' '---disable-inotify'; do
  31. > out || framework_failure_
  32. tail $mode -f $fastpoll < in > out 2> err & pid=$!
  33. # Wait up to 12.7s for output to appear:
  34. tail_re='line' retry_delay_ check_tail_output .1 7 ||
  35. { echo "$0: a: unexpected delay?"; cat out; fail=1; }
  36. # Ensure there was no error output.
  37. compare /dev/null err || fail=1
  38. cleanup_
  39. done
  40. #################
  41. # Before coreutils-8.26 this would induce an UMR under UBSAN
  42. returns_ 1 timeout 10 tail -f - <&- 2>errt || fail=1
  43. cat <<\EOF >exp || framework_failure_
  44. tail: cannot fstat 'standard input'
  45. tail: error reading 'standard input'
  46. tail: no files remaining
  47. tail: -
  48. EOF
  49. sed 's/\(tail:.*\):.*/\1/' errt > err || framework_failure_
  50. compare exp err || fail=1
  51. #################
  52. # Before coreutils-8.28 this would erroneously issue a warning
  53. if tty -s </dev/tty && test -t 0; then
  54. for input in '' '-' '/dev/tty'; do
  55. returns_ 124 timeout 0.1 tail -f $input 2>err || fail=1
  56. compare /dev/null err || fail=1
  57. done
  58. tail -f - /dev/null </dev/tty 2> out & pid=$!
  59. # Wait up to 12.7s for output to appear:
  60. tail_re='ineffective' retry_delay_ check_tail_output .1 7 ||
  61. { cat out; fail=1; }
  62. cleanup_
  63. fi
  64. Exit $fail