* init.cfg (trap_sigpipe_or_skip_): A new function refactored from...
* tests/misc/printf-surprise.sh: ...here.
* tests/misc/seq-epipe.sh. Likewise.
* src/tail.c (die_pipe): Ensure we exit upon sending SIGPIPE.
* tests/tail-2/pipe-f.sh: Ensure we exit even if SIGPIPE is ignored.
* NEWS: Mention the bug fix.
'tail -f file | filter' no longer exits immediately on AIX.
[bug introduced in coreutils-8.28]
+ 'tail -f file | filter' no longer goes into an infinite loop
+ if filter exits and SIGPIPE is ignored.
+ [bug introduced in coreutils-8.28]
+
** Changes in behavior
echo now always processes backslash escapes when the POSIXLY_CORRECT
fi
}
+trap_sigpipe_or_skip_()
+{
+ (trap '' PIPE && yes | :) 2>&1 | grep -qF 'Broken pipe' ||
+ skip_ 'trapping SIGPIPE is not supported'
+}
+
# Disable the current test if the working directory seems to have
# the setgid bit set.
skip_if_setgid_()
exit (status);
}
+/* Ensure exit, either with SIGPIPE or EXIT_FAILURE status. */
+static void ATTRIBUTE_NORETURN
+die_pipe (void)
+{
+ raise (SIGPIPE);
+ exit (EXIT_FAILURE);
+}
+
/* If the output has gone away, then terminate
as we would if we had written to this output. */
static void
pfd.events = POLLERR;
if (poll (&pfd, 1, 0) >= 0 && (pfd.revents & POLLERR))
- raise (SIGPIPE);
+ die_pipe ();
#else
struct timeval delay;
delay.tv_sec = delay.tv_usec = 0;
/* readable event on STDOUT is equivalent to POLLERR,
and implies an error condition on output like broken pipe. */
if (select (STDOUT_FILENO + 1, &rfd, NULL, NULL, &delay) == 1)
- raise (SIGPIPE);
+ die_pipe ();
#endif
}
{
/* readable event on STDOUT is equivalent to POLLERR,
and implies an error on output like broken pipe. */
- raise (SIGPIPE);
+ die_pipe ();
}
else
break;
# triggering the printf(3) misbehavior -- which, btw, is required by ISO C99.
mkfifo_or_skip_ fifo
-
-(trap '' PIPE && yes | :) 2>&1 | grep -qF 'Broken pipe' ||
- skip_ 'trapping SIGPIPE is not supported'
+trap_sigpipe_or_skip_
# Disable MALLOC_PERTURB_, to avoid triggering this bug
# https://bugs.debian.org/481543#77
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ seq
-
-(trap '' PIPE && yes | :) 2>&1 | grep -qF 'Broken pipe' ||
- skip_ 'trapping SIGPIPE is not supported'
+trap_sigpipe_or_skip_
# upon EPIPE with signals ignored, 'seq' should exit with an error.
timeout 10 sh -c \
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ tail
+trap_sigpipe_or_skip_
# Speedup the non inotify case
fastpoll='-s.1 --max-unchanged-stats=1'
compare exp out || fail=1
# This would wait indefinitely before v8.28 due to no EPIPE being
-# generated due to no data written after the first small amount
-(returns_ 124 timeout 10 tail -n2 -f $mode $fastpoll out && touch timed_out) |
- sed 2q > out2
-test -e timed_out && fail=1
-compare exp out2 || fail=1
+# generated due to no data written after the first small amount.
+# Also check tail exits if SIGPIPE is being ignored.
+# Note 'trap - SIGPIPE' is ineffective if the initiating shell
+# has ignored SIGPIPE, but that's not the normal case.
+for disposition in '' '-'; do
+ (trap "$disposition" PIPE;
+ returns_ 124 timeout 10 \
+ tail -n2 -f $mode $fastpoll out && touch timed_out) |
+ sed 2q > out2
+ test -e timed_out && fail=1
+ compare exp out2 || fail=1
+ rm -f timed_out
+done
# This would wait indefinitely before v8.28 (until first write)
(returns_ 1 timeout 10 tail -f $mode $fastpoll /dev/null >&-) || fail=1