[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ignored SIGPIPE (Darwin vs. cat)
From: |
Bruno Haible |
Subject: |
Re: ignored SIGPIPE (Darwin vs. cat) |
Date: |
Wed, 4 Mar 2009 01:37:35 +0100 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote:
> When running test-closein.sh, I'm getting spurious output on Darwin:
>
> cat: standard output: Bad file descriptor
> PASS: test-closein.sh
How to reproduce? On Darwin 7 and 9 (MacOS X 10.3.x and 10.9.x) I reproduce an
error from
$ cat foo | :
or
$ { sleep 1; cat foo; } | :
only if I previously issued the command
$ trap '' SIGPIPE
By default, or by using
$ trap '-' SIGPIPE
or
$ trap 'echo caught' SIGPIPE
I don't see an error.
> -# Test for lack of error on pipe
> -cat ${p}in.tmp | ./test-closein${EXEEXT} || exit 1
> +# Test for lack of error on pipe. Ignore any EPIPE failures from cat.
> +cat ${p}in.tmp 2>/dev/null | ./test-closein${EXEEXT} || exit 1
Changes like this reduce the reliability and debuggability of shell scripts,
because you throw away *all* kinds of error output. If there was a typo
in the word 'cat', or the program did not find its shared libraries, or
is symlinks to an /etc/alternatives/cat which is misconfigured, or similar
general errors, we *want* to see the error message.
Is the situation where SIGPIPE is ignored a recurrent one? Sam Steingold
reported apparently this situation, now you too. I would prefer to add a
catch-all clause to the beginning of all tests which use pipes:
#!/bin/sh
if trap | grep "^trap -- ['\"]['\"] SIGPIPE\$" > /dev/null; then
echo "Skipping test: SIGPIPE is ignored"
exit 77
fi
Now to the Darwin specific part of your mail:
> $ echo hi > foo
> $ cat foo | :
> cat: standard output: Bad file descriptor
> $ cat foo | { :; sleep 0.01; }
> $
>
> It seems like the Darwin kernel is failing to give SIGPIPE/EPIPE failures,
> and instead gives EBADF when the read end of the pipe is gone.
On MacOS X 10.3.x and 10.5.x with bash 2 or bash 3 I see:
$ trap '' SIGPIPE
$ { sleep 1; cat foo; } | :
cat: write error: Broken pipe
What's the version of your shell? The problem might lie in the ':' built-in
command of the shell.
Bruno