maint: list Gnulib sys_types directly
[coreutils.git] / tests / tail / follow-stdin.sh
blob799353a0e48bf3a15d93e8a78e221e2b59f6e4af
1 #!/bin/sh
2 # Test tail -f -
4 # Copyright (C) 2009-2024 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.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ tail
22 #################
23 # tail -f - would fail with the initial inotify implementation
25 check_tail_output()
27 local delay="$1"
28 grep "$tail_re" out ||
29 { sleep $delay; return 1; }
32 # Terminate any background tail process
33 cleanup_() { kill $pid 2>/dev/null && wait $pid; }
35 # Speedup the non inotify case
36 fastpoll='-s.1 --max-unchanged-stats=1'
38 echo line > in || framework_failure_
39 echo line > exp || framework_failure_
41 for mode in '' '---disable-inotify'; do
42 > out || framework_failure_
44 tail $mode -f $fastpoll < in > out 2> err & pid=$!
46 # Wait up to 12.7s for output to appear:
47 tail_re='line' retry_delay_ check_tail_output .1 7 ||
48 { echo "$0: a: unexpected delay?"; cat out; fail=1; }
50 # Ensure there was no error output.
51 compare /dev/null err || fail=1
53 cleanup_
54 done
57 #################
58 # Before coreutils-8.26 this would induce an UMR under UBSAN
59 returns_ 1 timeout 10 tail -f - <&- 2>errt || fail=1
60 cat <<\EOF >exp || framework_failure_
61 tail: cannot fstat 'standard input'
62 tail: error reading 'standard input'
63 tail: no files remaining
64 tail: -
65 EOF
66 sed 's/\(tail:.*\):.*/\1/' errt > err || framework_failure_
67 compare exp err || fail=1
70 #################
71 # Before coreutils-8.28 this would erroneously issue a warning
72 if tty -s </dev/tty && test -t 0; then
73 for input in '' '-' '/dev/tty'; do
74 returns_ 124 timeout 0.1 tail -f $input 2>err || fail=1
75 compare /dev/null err || fail=1
76 done
78 tail -f - /dev/null </dev/tty 2> out & pid=$!
79 # Wait up to 12.7s for output to appear:
80 tail_re='ineffective' retry_delay_ check_tail_output .1 7 ||
81 { cat out; fail=1; }
82 cleanup_
85 Exit $fail