maint: list Gnulib sys_types directly
[coreutils.git] / tests / tail / inotify-race.sh
blobe284d419cde3a1d14b5386fcc5954202b1e55af0
1 #!/bin/sh
2 # Ensure that tail does not ignore data that is appended to a tailed-forever
3 # file between tail's initial read-to-EOF, and when the inotify watches
4 # are established in tail_forever_inotify. That data could be ignored
5 # indefinitely if no *other* data is appended, but it would be printed as
6 # soon as any additional appended data is detected.
8 # Copyright (C) 2009-2024 Free Software Foundation, Inc.
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <https://www.gnu.org/licenses/>.
23 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
24 print_ver_ tail sleep
26 grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null && is_local_dir_ . \
27 || skip_ 'inotify is not supported'
29 # Terminate any background gdb/tail process
30 cleanup_() {
31 kill $pid 2>/dev/null && wait $pid
32 kill $sleep 2>/dev/null && wait $sleep
35 touch file || framework_failure_
36 touch tail.out || framework_failure_
38 ( timeout 10s gdb --version ) > gdb.out 2>&1
39 case $(cat gdb.out) in
40 *'GNU gdb'*) ;;
41 *) skip_ "can't run gdb";;
42 esac
44 # Break on a line rather than a symbol, to cater for inline functions
45 break_src="$abs_top_srcdir/src/tail.c"
46 break_line=$(grep -n ^tail_forever_inotify "$break_src") || framework_failure_
47 break_line=$(echo "$break_line" | cut -d: -f1) || framework_failure_
50 # Note we get tail to monitor a background sleep process
51 # rather than using timeout(1), as timeout sends SIGCONT
52 # signals to its monitored process, and gdb (7.9 at least)
53 # has _intermittent_ issues with this.
54 # Sending SIGCONT resulted in either delayed child termination,
55 # or no child termination resulting in a hung test.
56 # See https://sourceware.org/bugzilla/show_bug.cgi?id=18364
58 env sleep 10 & sleep=$!
60 # See if gdb works and
61 # tail_forever_inotify is compiled and run
62 gdb -nx --batch-silent \
63 --eval-command="break $break_line" \
64 --eval-command="run --pid=$sleep -f file" \
65 --eval-command='quit' \
66 tail < /dev/null > gdb.out 2>&1
68 kill $sleep || skip_ 'breakpoint not hit'
69 wait $sleep
71 # FIXME: The above is seen to _intermittently_ fail with:
72 # warning: .dynamic section for "/lib/libc.so.6" is not at the expected address
73 # warning: difference appears to be caused by prelink, adjusting expectations
74 compare /dev/null gdb.out || skip_ "can't set breakpoints in tail"
76 env sleep 10 & sleep=$!
78 # Run "tail -f file", stopping to append a line just before
79 # inotify initialization, and then continue. Before the fix,
80 # that just-appended line would never be output.
81 gdb -nx --batch-silent \
82 --eval-command="break $break_line" \
83 --eval-command="run --pid=$sleep -f file >> tail.out" \
84 --eval-command='shell echo never-seen-with-tail-7.5 >> file' \
85 --eval-command='continue' \
86 --eval-command='quit' \
87 tail < /dev/null > /dev/null 2>&1 & pid=$!
89 tail --pid=$pid -f tail.out | (read REPLY; kill $pid)
91 # gdb has a bug in Debian's gdb-6.8-3 at least that causes it to not
92 # cleanup and exit correctly when it receives a SIGTERM, but
93 # killing sleep, should cause the tail process and thus gdb to exit.
94 kill $sleep
95 wait $sleep
97 wait $pid
99 compare /dev/null tail.out && fail=1
101 Exit $fail