|
Packit |
709fb3 |
#!/bin/sh
|
|
Packit |
709fb3 |
# Check that a write failure with errno == EPIPE
|
|
Packit |
709fb3 |
# doesn't cause grep to issue multiple "write error" diagnostics.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
. "${srcdir=.}/init.sh"; path_prepend_ ../src
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
if
|
|
Packit |
709fb3 |
# Use awk to output a bounded amount of data to the grep in question,
|
|
Packit |
709fb3 |
# so that the test doesn't loop forever if grep is buggy.
|
|
Packit |
709fb3 |
# Use an explicit /dev/null for the benefit of older (pre-POSIX) awks.
|
|
Packit |
709fb3 |
#
|
|
Packit |
709fb3 |
# Carefully close fd 3 when not needed, as a sanity check.
|
|
Packit |
709fb3 |
#
|
|
Packit |
709fb3 |
# Do not use "trap - PIPE" or "trap 'something' PIPE" here, since we may
|
|
Packit |
709fb3 |
# be running in an environment where SIGPIPE is ignored, and in such an
|
|
Packit |
709fb3 |
# environment POSIX says that "trap '' PIPE" is all we can do portably.
|
|
Packit |
709fb3 |
(
|
|
Packit |
709fb3 |
${AWK-awk} 'BEGIN { for (i=0; i<1000000; i++) print i; }' /dev/null 3>&- |
|
|
Packit |
709fb3 |
(trap '' PIPE; exec grep . 2>&3 3>&-) |
|
|
Packit |
709fb3 |
:
|
|
Packit |
709fb3 |
) 3>&1 | (
|
|
Packit |
709fb3 |
read line1 && echo >&2 "$line1" &&
|
|
Packit |
709fb3 |
read line2 && echo >&2 "$line2"
|
|
Packit |
709fb3 |
)
|
|
Packit |
709fb3 |
then fail=1
|
|
Packit |
709fb3 |
else fail=0
|
|
Packit |
709fb3 |
fi
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
Exit $fail
|