[PATCH] Re: SIGPIPE and tee

Denys Vlasenko vda.linux at googlemail.com
Mon Oct 7 12:27:33 UTC 2019


On Fri, Oct 4, 2019 at 11:20 AM Sam Liddicott <sam at liddicott.com> wrote:
> nudge on this attached patch
>
> ---------- Forwarded message ---------
> From: Sam Liddicott <sam at liddicott.com>
> Date: Fri, 13 Sep 2019 at 11:15
> Subject: Re: SIGPIPE and tee
> To: busybox <busybox at busybox.net>
>
>
> Here is a patch which invokes kill_myself_with_sig(SIGPIPE) if fwrite fails with errno=EPIPE.
>
> Quitting with a signal rather than a diagnostic output emulates GNU tee which is in line with the apparent reason for busybox tee in ignoring SIGPIPE in the first place.


>
> I have tested it with and without CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
>
> As expected, dd succeeds for bs=1024 with CONFIG_FEATURE_TEE_USE_BLOCK_IO=y but fails for without.
> dd fails in both cases for bs=1024000
> tee fails in both cases
>
> ( sleep 2 ; dd if=/dev/zero bs=1024000 count=5 ; echo dd $? > /dev/tty ; ) | { build_output/sysroots-components/x86_64/busybox-native/bin/busybox.nosuid tee /dev/null ; echo tee $? >/dev/tty ; } | sleep 1
>
> ( sleep 2 ; dd if=/dev/zero bs=1024 count=5 ; echo dd $? > /dev/tty ; ) | { build_output/sysroots-components/x86_64/busybox-native/bin/busybox.nosuid tee /dev/null ; echo tee $? >/dev/tty ; } | sleep 1
>
> A colleague has suggested that any write failure to stdout by tee ought to cause tee to quit, but I leave this to your consideration; something like this might cover both cases but I haven't tested it:
>
> if (fwrite(buf, 1, c, *fp) != c) {
>   if (errno == EPIPE) kill_myself_with_sig(SIGPIPE);
>   retval = EXIT_FAILURE;
>   break;
> }
>
> Sam
>
>
> On Thu, 12 Sep 2019 at 20:03, Sam Liddicott <sam at liddicott.com> wrote:
>>
>> In  https://git.busybox.net/busybox/tree/coreutils/tee.c we read:
>>
>> /* gnu tee ignores SIGPIPE in case one of the output files is a pipe
>> * that doesn't consume all its input.  Good idea... */
>> signal(SIGPIPE, SIG_IGN);
>>
>>
>> Sadly, this breaks POSIX SIGPIPE behaviour with respect to quitting when stdout (as a pipe) is closed.
>>
>> Despite the comment, GNU tee does not behave as the comment suggests.

Exactly. GNU tee does not intercept SIGPIPE (unless -p is given).
I'm removing SIGPIPE handling.
Please try current git.


More information about the busybox mailing list