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