On 01/03/2020 20:23, Bruno Haible wrote:
On Solaris 11 OpenIndiana, I observe a test error:
ERROR: tests/misc/env-signal-handler
====================================
--- exp-err1 Sat Feb 29 00:36:58 2020
+++ err1 Sat Feb 29 00:36:58 2020
@@ -1,1 +1,0 @@
-seq: write error:
env-signal-handler.sh: set-up failure:
ERROR tests/misc/env-signal-handler.sh (exit status: 99)
On this platform, the file 'err1t' created through the command
(trap '' PIPE; $SHELL -c 'trap - PIPE; seq 999999 2>err1t | head -n1 > out1')
sometimes contains the expected message "seq: write error: Broken pipe",
sometimes it is empty. Most often it's as expected in the first 3 out of 20
runs:
$ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do (trap '' PIPE; /bin/sh -c
'trap - PIPE; seq 999999 2>err1t | head -n1 > out1') ; echo "Round $i:"; cat
err1t; done
Round 0:
seq: write error: Broken pipe
Round 1:
seq: write error: Broken pipe
Round 2:
seq: write error: Broken pipe
Round 3:
Round 4:
Round 5:
Round 6:
Round 7:
Round 8:
Round 9:
Round 10:
Round 11:
Round 12:
Round 13:
Round 14:
Round 15:
Round 16:
Round 17:
Round 18:
Round 19:
Sometimes it's the first 5 out of 20 runs; sometimes the first 3 and the 9th
run.
So, it looks like a timing issue, as if the 'trap - PIPE' command takes a couple
of milliseconds until it becomes effective.
If I add a delay, I get mostly the expected output:
$ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do (trap '' PIPE; /bin/sh -c
'trap - PIPE; sleep 1; seq 999999 2>err1t | head -n1 > out1') ; echo "Round
$i:"; cat err1t; done
Round 0:
seq: write error: Broken pipe
Round 1:
seq: write error: Broken pipe
Round 2:
seq: write error: Broken pipe
Round 3:
seq: write error: Broken pipe
Round 4:
seq: write error: Broken pipe
Round 5:
Round 6:
seq: write error: Broken pipe
Round 7:
seq: write error: Broken pipe
Round 8:
seq: write error: Broken pipe
Round 9:
seq: write error: Broken pipe
Round 10:
seq: write error: Broken pipe
Round 11:
seq: write error: Broken pipe
Round 12:
seq: write error: Broken pipe
Round 13:
seq: write error: Broken pipe
Round 14:
seq: write error: Broken pipe
Round 15:
seq: write error: Broken pipe
Round 16:
seq: write error: Broken pipe
Round 17:
seq: write error: Broken pipe
Round 18:
seq: write error: Broken pipe
Round 19:
seq: write error: Broken pipe
If I use bash instead of /bin/sh, the output is all right:
$ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do (trap '' PIPE; /usr/bin/bash
-c 'trap - PIPE; seq 999999 2>err1t | head -n1 > out1') ; echo "Round $i:"; cat
err1t; done
Round 0:
seq: write error: Broken pipe
Round 1:
seq: write error: Broken pipe
Round 2:
seq: write error: Broken pipe
Round 3:
seq: write error: Broken pipe
Round 4:
seq: write error: Broken pipe
Round 5:
seq: write error: Broken pipe
Round 6:
seq: write error: Broken pipe
Round 7:
seq: write error: Broken pipe
Round 8:
seq: write error: Broken pipe
Round 9:
seq: write error: Broken pipe
Round 10:
seq: write error: Broken pipe
Round 11:
seq: write error: Broken pipe
Round 12:
seq: write error: Broken pipe
Round 13:
seq: write error: Broken pipe
Round 14:
seq: write error: Broken pipe
Round 15:
seq: write error: Broken pipe
Round 16:
seq: write error: Broken pipe
Round 17:
seq: write error: Broken pipe
Round 18:
seq: write error: Broken pipe
Round 19:
seq: write error: Broken pipe
But the value of SHELL in config.status is /bin/sh. Apparently /bin/sh is
good enough for nearly everything, just not for this 'trap - PIPE' command.
I'm not sure what is the best way forward: Use bash here instead of $SHELL
whenever it is found in $PATH ?
Nice debugging.
It's a pity the failure is intermittent, as then one might
be able to add a check to gl_shell_test_script_ in gnulib/tests/init.sh,
to exclude the problematic shell. Though that might be a bit
draconian for only this particular issue.
I guess we should switch to bash for these cases.
bash is common enough to result in skips on few systems.
The attached should do that.
thanks!
Pádraig.
>From 2c957ea5baa2a9f66e2d0309ce61dc7200d01e7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Sun, 1 Mar 2020 21:49:16 +0000
Subject: [PATCH] tests: use bash in some scripts on avoid false failures
* init.cfg (require_bash_as_SHELL_): A new function to replace
SHELL for the current test, with bash if available.
This is useful on OpenIndiana 11 where /bin/sh was seen
to have races in handling of SIGPIPE.
* tests/misc/seq-epipe.sh: Use the new function to enforce bash.
* tests/misc/env-signal-handler.sh: Likewise.
Reported by Bruno Haible
---
init.cfg | 9 +++++++++
tests/misc/env-signal-handler.sh | 5 +++++
tests/misc/seq-epipe.sh | 7 ++++++-
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/init.cfg b/init.cfg
index 2009e294e..8385963f4 100644
--- a/init.cfg
+++ b/init.cfg
@@ -629,6 +629,15 @@ trap_sigpipe_or_skip_()
skip_ 'trapping SIGPIPE is not supported'
}
+require_bash_as_SHELL_()
+{
+ if bash --version >/dev/null 2>&1; then
+ SHELL='bash'
+ else
+ skip_ 'bash is required'
+ fi
+}
+
# Disable the current test if the working directory seems to have
# the setgid bit set.
skip_if_setgid_()
diff --git a/tests/misc/env-signal-handler.sh b/tests/misc/env-signal-handler.sh
index fc1bb4e7d..c38177dae 100755
--- a/tests/misc/env-signal-handler.sh
+++ b/tests/misc/env-signal-handler.sh
@@ -20,6 +20,11 @@
print_ver_ env seq test timeout printf
trap_sigpipe_or_skip_
+# /bin/sh has an intermittent failure in ignoring SIGPIPE on OpenIndiana 11
+# so we require bash as discussed at:
+# https://lists.gnu.org/archive/html/coreutils/2020-03/msg00004.html
+require_bash_as_SHELL_
+
# Paraphrasing http://bugs.gnu.org/34488#8:
# POSIX requires that sh started with an inherited ignored SIGPIPE must
# silently ignore all attempts from within the shell to restore SIGPIPE
diff --git a/tests/misc/seq-epipe.sh b/tests/misc/seq-epipe.sh
index fe11e61f5..0c42e4308 100755
--- a/tests/misc/seq-epipe.sh
+++ b/tests/misc/seq-epipe.sh
@@ -20,8 +20,13 @@
print_ver_ seq
trap_sigpipe_or_skip_
+# /bin/sh has an intermittent failure in ignoring SIGPIPE on OpenIndiana 11
+# so we require bash as discussed at:
+# https://lists.gnu.org/archive/html/coreutils/2020-03/msg00004.html
+require_bash_as_SHELL_
+
# upon EPIPE with signals ignored, 'seq' should exit with an error.
-timeout 10 sh -c \
+timeout 10 $SHELL -c \
'trap "" PIPE && { seq inf 2>err; echo $? >code; } | head -n1' >out
# Exit-code must be 1, indicating 'write error'
--
2.24.1