2 # Makes sure, inotify will switch to polling mode if directory
3 # of the watched file was removed and recreated.
4 # (...instead of getting stuck forever)
6 # Copyright (C) 2017-2024 Free Software Foundation, Inc.
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.
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.
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/>.
21 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
24 grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev
/null
&& is_local_dir_ . \
25 || skip_
'inotify is not supported'
27 # Terminate any background tail process
28 cleanup_
() { kill $pid 2>/dev
/null
&& wait $pid; }
37 # $check_re - string to be found
38 # $check_f - file to be searched
42 grep $check_re $check_f > /dev
/null ||
43 { sleep $delay ; return 1; }
50 retry_delay_ check_tail_output_
.1 5
53 # Prepare the file to be watched
54 mkdir dir
&& echo 'inotify' > dir
/file || framework_failure_
56 #tail must print content of the file to stdout, verify
57 timeout
60 tail --pid=$$
-F dir
/file >out
2>&1 & pid
=$
!
58 grep_timeout_
'inotify' 'out' ||
59 { cleanup_fail_
'file to be tailed does not exist'; }
61 inotify_failed_re
='inotify (resources exhausted|cannot be used)'
62 grep -E "$inotify_failed_re" out
&&
63 skip_
"inotify can't be used"
65 # Remove the directory, should get the message about the deletion
66 rm -r dir || framework_failure_
67 grep_timeout_
'polling' 'out' ||
68 { cleanup_fail_
'tail did not switch to polling mode'; }
70 # Recreate the dir, must get a message about recreation
71 mkdir dir
&& touch dir
/file || framework_failure_
72 grep_timeout_
'appeared' 'out' ||
73 { cleanup_fail_
'previously removed file did not appear'; }
77 # Expected result for the whole process
78 cat <<\EOF
> exp || framework_failure_
80 tail: 'dir/file' has become inaccessible
: No such
file or directory
81 tail: directory containing watched
file was removed
82 tail: inotify cannot be used
, reverting to polling
83 tail: 'dir/file' has appeared
; following new
file
86 compare exp out || fail
=1