aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/tests
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2019-02-24 21:05:13 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2019-02-24 21:05:13 +0000
commit484160a9cf236a5892c1ab8344de287d7a1472c1 (patch)
tree94a5b8ec59cc907d087292016bcd42bef385135d /bin/sh/tests
parentdd3a67a0781261c1fdd670456f492ecb695b8fe5 (diff)
downloadsrc-484160a9cf236a5892c1ab8344de287d7a1472c1.tar.gz
src-484160a9cf236a5892c1ab8344de287d7a1472c1.zip
sh: Add set -o pipefail
The pipefail option allows checking the exit status of all commands in a pipeline more easily, at a limited cost of complexity in sh itself. It works similarly to the option in bash, ksh93 and mksh. Like ksh93 and unlike bash and mksh, the state of the option is saved when a pipeline is started. Therefore, even in the case of commands like A | B & a later change of the option does not change the exit status, the same way (A | B) & works. Since SIGPIPE is not handled specially, more work in the script is required for a proper exit status for pipelines containing commands such as head that may terminate successfully without reading all input. This can be something like ( cmd1 r=$? if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then exit 0 else exit "$r" fi ) | head PR: 224270 Relnotes: yes
Notes
Notes: svn path=/head/; revision=344502
Diffstat (limited to 'bin/sh/tests')
-rw-r--r--bin/sh/tests/execution/Makefile7
-rw-r--r--bin/sh/tests/execution/pipefail1.04
-rw-r--r--bin/sh/tests/execution/pipefail2.424
-rw-r--r--bin/sh/tests/execution/pipefail3.424
-rw-r--r--bin/sh/tests/execution/pipefail4.424
-rw-r--r--bin/sh/tests/execution/pipefail5.425
-rw-r--r--bin/sh/tests/execution/pipefail6.426
-rw-r--r--bin/sh/tests/execution/pipefail7.05
8 files changed, 39 insertions, 0 deletions
diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile
index a5c1cee95ddb..c8fac417de85 100644
--- a/bin/sh/tests/execution/Makefile
+++ b/bin/sh/tests/execution/Makefile
@@ -31,6 +31,13 @@ ${PACKAGE}FILES+= killed2.0
${PACKAGE}FILES+= not1.0
${PACKAGE}FILES+= not2.0
${PACKAGE}FILES+= path1.0
+${PACKAGE}FILES+= pipefail1.0
+${PACKAGE}FILES+= pipefail2.42
+${PACKAGE}FILES+= pipefail3.42
+${PACKAGE}FILES+= pipefail4.42
+${PACKAGE}FILES+= pipefail5.42
+${PACKAGE}FILES+= pipefail6.42
+${PACKAGE}FILES+= pipefail7.0
${PACKAGE}FILES+= redir1.0
${PACKAGE}FILES+= redir2.0
${PACKAGE}FILES+= redir3.0
diff --git a/bin/sh/tests/execution/pipefail1.0 b/bin/sh/tests/execution/pipefail1.0
new file mode 100644
index 000000000000..df23a012ca07
--- /dev/null
+++ b/bin/sh/tests/execution/pipefail1.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -o pipefail
+: && : | : && : | : | : && : | : | : | :
diff --git a/bin/sh/tests/execution/pipefail2.42 b/bin/sh/tests/execution/pipefail2.42
new file mode 100644
index 000000000000..b9092661c76e
--- /dev/null
+++ b/bin/sh/tests/execution/pipefail2.42
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -o pipefail
+(exit 42) | :
diff --git a/bin/sh/tests/execution/pipefail3.42 b/bin/sh/tests/execution/pipefail3.42
new file mode 100644
index 000000000000..d96602b57f02
--- /dev/null
+++ b/bin/sh/tests/execution/pipefail3.42
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -o pipefail
+: | (exit 42)
diff --git a/bin/sh/tests/execution/pipefail4.42 b/bin/sh/tests/execution/pipefail4.42
new file mode 100644
index 000000000000..3399dd8c4452
--- /dev/null
+++ b/bin/sh/tests/execution/pipefail4.42
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -o pipefail
+(exit 43) | (exit 42)
diff --git a/bin/sh/tests/execution/pipefail5.42 b/bin/sh/tests/execution/pipefail5.42
new file mode 100644
index 000000000000..4effb2b3301e
--- /dev/null
+++ b/bin/sh/tests/execution/pipefail5.42
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+set -o pipefail
+(exit 42) | : &
+wait %+
diff --git a/bin/sh/tests/execution/pipefail6.42 b/bin/sh/tests/execution/pipefail6.42
new file mode 100644
index 000000000000..7395d8c785a6
--- /dev/null
+++ b/bin/sh/tests/execution/pipefail6.42
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -o pipefail
+(exit 42) | : &
+set +o pipefail
+wait %+
diff --git a/bin/sh/tests/execution/pipefail7.0 b/bin/sh/tests/execution/pipefail7.0
new file mode 100644
index 000000000000..797d485f3c61
--- /dev/null
+++ b/bin/sh/tests/execution/pipefail7.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+(exit 42) | : &
+set -o pipefail
+wait %+