summaryrefslogtreecommitdiff
path: root/tests/tail-2/wait.sh
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2015-07-04 17:13:50 +0300
committerIgor Pashev <pashev.igor@gmail.com>2015-07-04 17:13:50 +0300
commit71cd8e3a743046573744123777061b64881bf372 (patch)
tree82522befe647f4fff186a5630cad0cad33f8ef53 /tests/tail-2/wait.sh
parentc18578632fd3c9e513e613a86ba2b7c4ebee6c45 (diff)
downloadcoreutils-upstream.tar.gz
Imported Upstream version 8.24upstream/8.24upstream
Diffstat (limited to 'tests/tail-2/wait.sh')
-rwxr-xr-xtests/tail-2/wait.sh46
1 files changed, 31 insertions, 15 deletions
diff --git a/tests/tail-2/wait.sh b/tests/tail-2/wait.sh
index 3dec55c0..2e58e821 100755
--- a/tests/tail-2/wait.sh
+++ b/tests/tail-2/wait.sh
@@ -2,7 +2,7 @@
# Make sure that 'tail -f' returns immediately if a file doesn't exist
# while 'tail -F' waits for it to appear.
-# Copyright (C) 2003-2014 Free Software Foundation, Inc.
+# Copyright (C) 2003-2015 Free Software Foundation, Inc.
# 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
@@ -20,47 +20,60 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ tail
+grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null \
+ && HAVE_INOTIFY=1
+
+inotify_failed_re='inotify (resources exhausted|cannot be used)'
+
touch here || framework_failure_
{ touch unreadable && chmod a-r unreadable; } || framework_failure_
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
+# speedup non inotify case
+fastpoll='-s.1 --max-unchanged-stats=1'
-for inotify in ---disable-inotify ''; do
- timeout 10 tail -s0.1 -f $inotify not_here
+for mode in '' '---disable-inotify'; do
+ timeout 10 tail $fastpoll -f $mode not_here
test $? = 124 && fail=1
if test ! -r unreadable; then # can't test this when root
- timeout 10 tail -s0.1 -f $inotify unreadable
+ timeout 10 tail $fastpoll -f $mode unreadable
test $? = 124 && fail=1
fi
- timeout 1 tail -s0.1 -f $inotify here 2>tail.err
+ timeout .1 tail $fastpoll -f $mode here 2>tail.err
test $? = 124 || fail=1
# 'tail -F' must wait in any case.
- timeout 1 tail -s0.1 -F $inotify here 2>>tail.err
+ timeout .1 tail $fastpoll -F $mode here 2>>tail.err
test $? = 124 || fail=1
if test ! -r unreadable; then # can't test this when root
- timeout 1 tail -s0.1 -F $inotify unreadable
+ timeout .1 tail $fastpoll -F $mode unreadable
test $? = 124 || fail=1
fi
- timeout 1 tail -s0.1 -F $inotify not_here
+ timeout .1 tail $fastpoll -F $mode not_here
test $? = 124 || fail=1
- grep -Ev 'inotify (resources exhausted|cannot be used)' tail.err > x
+ grep -Ev "$inotify_failed_re" tail.err > x
mv x tail.err
compare /dev/null tail.err || fail=1
>tail.err
+done
+if test "$HAVE_INOTIFY"; then
+ # Ensure -F never follows a descriptor after rename
+ # either with tiny or significant delays between operations
tail_F()
{
local delay="$1"
touch k || framework_failure_
- tail -s.1 --max-unchanged-stats=2 -F $inotify k > tail.out &
- pid=$!
+ tail $fastpoll -F $mode k >tail.out 2>tail.err & pid=$!
sleep $delay
mv k l
sleep $delay
@@ -69,12 +82,15 @@ for inotify in ---disable-inotify ''; do
sleep $delay
echo NO >> l
sleep $delay
- kill $pid
+ cleanup_
rm -f k l
- test ! -s tail.out
+ test -s tail.out \
+ && ! grep -E "$inotify_failed_re" tail.err >/dev/null
}
- retry_delay_ tail_F .1 4 || fail=1
-done
+
+ retry_delay_ tail_F 0 1 && { cat tail.out; fail=1; }
+ retry_delay_ tail_F .2 1 && { cat tail.out; fail=1; }
+fi
Exit $fail