2009-06-02 08:28:23 +02:00
|
|
|
#!/bin/sh
|
2012-01-07 17:47:58 +01:00
|
|
|
# Make sure that 'tail -f' returns immediately if a file doesn't exist
|
|
|
|
|
# while 'tail -F' waits for it to appear.
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2026-01-01 10:56:16 -08:00
|
|
|
# Copyright (C) 2003-2026 Free Software Foundation, Inc.
|
2009-06-02 08:28:23 +02:00
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2017-09-19 01:13:23 -07:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2012-09-02 21:55:12 +02:00
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
2010-11-17 21:35:31 +01:00
|
|
|
print_ver_ tail
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2015-06-01 16:46:33 +01:00
|
|
|
grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null \
|
|
|
|
|
&& HAVE_INOTIFY=1
|
|
|
|
|
|
|
|
|
|
inotify_failed_re='inotify (resources exhausted|cannot be used)'
|
|
|
|
|
|
2011-08-04 20:52:31 +02:00
|
|
|
touch here || framework_failure_
|
|
|
|
|
{ touch unreadable && chmod a-r unreadable; } || framework_failure_
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2015-05-01 05:26:38 +01:00
|
|
|
# Terminate any background tail process
|
|
|
|
|
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
|
|
|
|
|
2015-05-02 10:52:37 +01:00
|
|
|
# speedup non inotify case
|
|
|
|
|
fastpoll='-s.1 --max-unchanged-stats=1'
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2015-05-02 10:52:37 +01:00
|
|
|
for mode in '' '---disable-inotify'; do
|
2016-11-08 19:57:41 -06:00
|
|
|
returns_ 124 timeout 10 tail $fastpoll -f $mode not_here && fail=1
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2009-09-04 21:41:30 +01:00
|
|
|
if test ! -r unreadable; then # can't test this when root
|
2016-11-08 19:57:41 -06:00
|
|
|
returns_ 124 timeout 10 tail $fastpoll -f $mode unreadable && fail=1
|
2009-09-04 21:41:30 +01:00
|
|
|
fi
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2016-11-08 19:57:41 -06:00
|
|
|
returns_ 124 timeout .1 tail $fastpoll -f $mode here 2>tail.err || fail=1
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2012-01-07 17:47:58 +01:00
|
|
|
# 'tail -F' must wait in any case.
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2016-11-08 19:57:41 -06:00
|
|
|
returns_ 124 timeout .1 tail $fastpoll -F $mode here 2>>tail.err || fail=1
|
2009-06-02 08:28:23 +02:00
|
|
|
|
2009-09-04 21:41:30 +01:00
|
|
|
if test ! -r unreadable; then # can't test this when root
|
2016-11-08 19:57:41 -06:00
|
|
|
returns_ 124 timeout .1 tail $fastpoll -F $mode unreadable || fail=1
|
2009-09-04 21:41:30 +01:00
|
|
|
fi
|
|
|
|
|
|
2016-11-08 19:57:41 -06:00
|
|
|
returns_ 124 timeout .1 tail $fastpoll -F $mode not_here || fail=1
|
2009-09-04 21:41:30 +01:00
|
|
|
|
2015-06-01 16:46:33 +01:00
|
|
|
grep -Ev "$inotify_failed_re" tail.err > x
|
2009-12-12 14:44:46 +01:00
|
|
|
mv x tail.err
|
2014-05-06 02:37:43 +01:00
|
|
|
compare /dev/null tail.err || fail=1
|
2014-03-05 18:41:16 +00:00
|
|
|
>tail.err
|
2015-06-01 16:46:33 +01:00
|
|
|
done
|
2009-09-04 21:41:30 +01:00
|
|
|
|
2016-01-19 18:45:07 +00:00
|
|
|
if test "$HAVE_INOTIFY" && test -z "$mode" && is_local_dir_ .; then
|
2015-05-02 10:52:37 +01:00
|
|
|
# Ensure -F never follows a descriptor after rename
|
|
|
|
|
# either with tiny or significant delays between operations
|
2010-07-05 08:53:10 +01:00
|
|
|
tail_F()
|
|
|
|
|
{
|
|
|
|
|
local delay="$1"
|
|
|
|
|
|
2016-01-10 01:44:04 +01:00
|
|
|
> k && > tail.out && > tail.err || framework_failure_
|
2025-09-18 17:47:45 +01:00
|
|
|
timeout 60 tail $fastpoll -F $mode k >tail.out 2>tail.err & pid=$!
|
2010-07-05 08:53:10 +01:00
|
|
|
sleep $delay
|
|
|
|
|
mv k l
|
|
|
|
|
sleep $delay
|
|
|
|
|
touch k
|
|
|
|
|
mv k l
|
|
|
|
|
sleep $delay
|
|
|
|
|
echo NO >> l
|
|
|
|
|
sleep $delay
|
2015-05-01 05:26:38 +01:00
|
|
|
cleanup_
|
2010-07-05 08:53:10 +01:00
|
|
|
rm -f k l
|
|
|
|
|
|
2015-06-01 16:46:33 +01:00
|
|
|
test -s tail.out \
|
|
|
|
|
&& ! grep -E "$inotify_failed_re" tail.err >/dev/null
|
2010-07-05 08:53:10 +01:00
|
|
|
}
|
2015-06-01 16:46:33 +01:00
|
|
|
|
2015-05-02 10:52:37 +01:00
|
|
|
retry_delay_ tail_F 0 1 && { cat tail.out; fail=1; }
|
|
|
|
|
retry_delay_ tail_F .2 1 && { cat tail.out; fail=1; }
|
2015-06-01 16:46:33 +01:00
|
|
|
fi
|
2009-06-02 08:28:23 +02:00
|
|
|
|
|
|
|
|
Exit $fail
|