summaryrefslogtreecommitdiffstats
path: root/src/grep/tests/epipe
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:21:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:21:29 +0000
commit29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc (patch)
tree63ef546b10a81d461e5cf5ed9e98a68cd7dee1aa /src/grep/tests/epipe
parentInitial commit. (diff)
downloadkbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.tar.xz
kbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.zip
Adding upstream version 1:0.1.9998svn3589+dfsg.upstream/1%0.1.9998svn3589+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/grep/tests/epipe')
-rwxr-xr-xsrc/grep/tests/epipe29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/grep/tests/epipe b/src/grep/tests/epipe
new file mode 100755
index 0000000..3b568e3
--- /dev/null
+++ b/src/grep/tests/epipe
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Check that a write failure with errno == EPIPE
+# doesn't cause grep to issue multiple "write error" diagnostics.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+if
+ # Use awk to output a bounded amount of data to the grep in question,
+ # so that the test doesn't loop forever if grep is buggy.
+ # Use an explicit /dev/null for the benefit of older (pre-POSIX) awks.
+ #
+ # Carefully close fd 3 when not needed, as a sanity check.
+ #
+ # Do not use "trap - PIPE" or "trap 'something' PIPE" here, since we may
+ # be running in an environment where SIGPIPE is ignored, and in such an
+ # environment POSIX says that "trap '' PIPE" is all we can do portably.
+ (
+ ${AWK-awk} 'BEGIN { for (i=0; i<1000000; i++) print i; }' /dev/null 3>&- |
+ (trap '' PIPE; exec grep . 2>&3 3>&-) |
+ :
+ ) 3>&1 | (
+ read line1 && echo >&2 "$line1" &&
+ read line2 && echo >&2 "$line2"
+ )
+then fail=1
+else fail=0
+fi
+
+Exit $fail