chown: warn about USER.GROUP
[coreutils.git] / tests / tail-2 / wait.sh
blobe9fc1fa5ec9bf5252df5f4a8bc4d4ec09dd72007
1 #!/bin/sh
2 # Make sure that 'tail -f' returns immediately if a file doesn't exist
3 # while 'tail -F' waits for it to appear.
5 # Copyright (C) 2003-2022 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21 print_ver_ tail
23 grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null \
24 && HAVE_INOTIFY=1
26 inotify_failed_re='inotify (resources exhausted|cannot be used)'
28 touch here || framework_failure_
29 { touch unreadable && chmod a-r unreadable; } || framework_failure_
31 # Terminate any background tail process
32 cleanup_() { kill $pid 2>/dev/null && wait $pid; }
34 # speedup non inotify case
35 fastpoll='-s.1 --max-unchanged-stats=1'
37 for mode in '' '---disable-inotify'; do
38 returns_ 124 timeout 10 tail $fastpoll -f $mode not_here && fail=1
40 if test ! -r unreadable; then # can't test this when root
41 returns_ 124 timeout 10 tail $fastpoll -f $mode unreadable && fail=1
44 returns_ 124 timeout .1 tail $fastpoll -f $mode here 2>tail.err || fail=1
46 # 'tail -F' must wait in any case.
48 returns_ 124 timeout .1 tail $fastpoll -F $mode here 2>>tail.err || fail=1
50 if test ! -r unreadable; then # can't test this when root
51 returns_ 124 timeout .1 tail $fastpoll -F $mode unreadable || fail=1
54 returns_ 124 timeout .1 tail $fastpoll -F $mode not_here || fail=1
56 grep -Ev "$inotify_failed_re" tail.err > x
57 mv x tail.err
58 compare /dev/null tail.err || fail=1
59 >tail.err
60 done
62 if test "$HAVE_INOTIFY" && test -z "$mode" && is_local_dir_ .; then
63 # Ensure -F never follows a descriptor after rename
64 # either with tiny or significant delays between operations
65 tail_F()
67 local delay="$1"
69 > k && > tail.out && > tail.err || framework_failure_
70 tail $fastpoll -F $mode k >tail.out 2>tail.err & pid=$!
71 sleep $delay
72 mv k l
73 sleep $delay
74 touch k
75 mv k l
76 sleep $delay
77 echo NO >> l
78 sleep $delay
79 cleanup_
80 rm -f k l
82 test -s tail.out \
83 && ! grep -E "$inotify_failed_re" tail.err >/dev/null
86 retry_delay_ tail_F 0 1 && { cat tail.out; fail=1; }
87 retry_delay_ tail_F .2 1 && { cat tail.out; fail=1; }
90 Exit $fail