[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: SIGPIPE and tee
From:       Sam Liddicott <sam () liddicott ! com>
Date:       2019-09-13 10:17:42
Message-ID: CAOj-5WC1SWGndRPdgvo+1dus6weXTjDJvFMYo-BMiOp_KXHVvQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I also note that busybox tee treats a filename single hyphen as stdout,
contrary to POSIX.

I mention it only because it might save a few bytes to remove this special
case, and treat it as a regular file.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html
OPERANDS

The following operands shall be supported:
*file*A pathname of an output file. If a *file* operand is '-', it shall
refer to a file named *-*; implementations shall not treat it as meaning
standard output.


On Thu, 12 Sep 2019 at 20:03, Sam Liddicott <sam@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.
> 
> Comparing 1.27.2-2ubuntu3.2 with tee (GNU coreutils) 8.28
> 
> I test with one output file and stdout that stops early causing SIGPIPE
> 
> 1. GNU tee
> 
> ( dd if=/dev/zero bs=1024 count=8192 ; echo done $? >&2  ) | ( tee
> /dev/null ; echo tee $? >&2) | dd bs=10 count=10 >/dev/null
> 
> 10+0 records in
> 10+0 records out
> 100 bytes copied, 0.000387276 s, 258 kB/s
> tee 141
> done 141
> 
> the first two pipeline stages have exit code 141 due to sigpipe as we
> would expect
> 
> 2. busybox tee
> 
> ( dd if=/dev/zero bs=1024 count=8192 ; echo done $? >&2  ) | ( busybox tee
> /dev/null ; echo tee $? >&2) | dd bs=10 count=10 >/dev/null
> 10+0 records in
> 10+0 records out
> 100 bytes copied, 0.000291134 s, 343 kB/s
> 8192+0 records in
> 8192+0 records out
> 8388608 bytes (8.4 MB, 8.0 MiB) copied, 0.0447136 s, 188 MB/s
> done 0
> tee 0
> 
> both prior pipeline elements have exit code zero and the first stage
> processed all of the data
> 
> The POSIX spec for tee reads:
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html
> CONSEQUENCES OF ERRORS
> 
> If a write to any successfully opened *file* operand fails, writes to
> other successfully opened *file* operands and standard output shall
> continue, but the exit status shall be non-zero. Otherwise, the default
> actions specified in *Utility Description Defaults*
> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html#tag_17_04>
>  apply.
> 
> But this case deals with a failure to write to stdout, not a failure to
> write to a *file* operand.
> 
> Certainly, with this behaviour, busybox tee does not comply with GNU tee
> as it appears to intend, so I suggest that the line signal(SIGPIPE,
> SIG_IGN) be removed.
> 
> To meet the probable intent, the signal should probably be ignored while
> writing to file operands (in case they turn out to be pipes) and enabled
> each time when writing to stdout.
> 
> Sam
> 


[Attachment #5 (text/html)]

<div dir="ltr">I also note that busybox tee treats a filename single hyphen as \
stdout, contrary to POSIX.<div><br></div><div>I mention it only because it might save \
a few bytes to remove this special case, and treat it as a regular file.<br><br><a \
href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html">https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html</a> \
<br></div><div><h4 class="gmail-mansect" \
style="color:rgb(0,102,0);font-style:italic;font-size:12pt">OPERANDS</h4><blockquote \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><p>The \
following operands shall be supported:</p><dl compact><dt><i>file</i></dt><dd>A \
pathname of an output file. If a  <i>file</i>  operand is  <tt>&#39;-&#39;</tt>, it \
shall refer to a file named  <b>-</b>; implementations shall not treat it as meaning \
standard output.</dd></dl></blockquote></div></div><br><div class="gmail_quote"><div \
dir="ltr" class="gmail_attr">On Thu, 12 Sep 2019 at 20:03, Sam Liddicott &lt;<a \
href="mailto:sam@liddicott.com">sam@liddicott.com</a>&gt; wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div dir="ltr">In  

<a href="https://git.busybox.net/busybox/tree/coreutils/tee.c" \
target="_blank">https://git.busybox.net/busybox/tree/coreutils/tee.c</a>  we \
read:<div><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px">	<span \
class="gmail-m_5126291428043663572gmail-cm" style="color:rgb(136,136,136)">/* gnu tee \
ignores SIGPIPE in case one of the output files is a pipe</span> <span \
class="gmail-m_5126291428043663572gmail-cm" style="color:rgb(136,136,136)">	 * that \
doesn&#39;t consume all its input.  Good idea... */</span>  <span \
class="gmail-m_5126291428043663572gmail-n">signal</span><span \
class="gmail-m_5126291428043663572gmail-p">(</span><span \
class="gmail-m_5126291428043663572gmail-n">SIGPIPE</span><span \
class="gmail-m_5126291428043663572gmail-p">,</span> <span \
class="gmail-m_5126291428043663572gmail-n">SIG_IGN</span><span \
class="gmail-m_5126291428043663572gmail-p">);</span></pre></div><div><br></div><div>Sadly, \
this breaks POSIX SIGPIPE behaviour with respect to quitting when stdout (as a pipe) \
is closed.</div><div><br></div><div>Despite the comment, GNU tee does not behave as \
the comment suggests.</div><div><br></div><div>Comparing  1.27.2-2ubuntu3.2 with  tee \
(GNU coreutils) 8.28</div><div><br></div><div>I test with one output file and stdout \
that stops early causing SIGPIPE</div><div><br></div><div>1. GNU \
tee</div><div><br></div><div>( dd if=/dev/zero bs=1024 count=8192 ; echo done $? \
&gt;&amp;2   ) | ( tee /dev/null ; echo tee $? &gt;&amp;2) | dd bs=10 count=10 \
&gt;/dev/null<br></div><div><br></div><div>10+0 records in<br>10+0 records out<br>100 \
bytes copied, 0.000387276 s, 258 kB/s<br>tee 141<br>done \
141<br></div><div><br></div><div>the first two pipeline stages have exit code 141 due \
to sigpipe as we would expect</div><div><br></div><div>2. busybox \
tee</div><div><br></div><div>( dd if=/dev/zero bs=1024 count=8192 ; echo done $? \
&gt;&amp;2   ) | ( busybox tee /dev/null ; echo tee $? &gt;&amp;2) | dd bs=10 \
count=10 &gt;/dev/null<br>10+0 records in<br>10+0 records out<br>100 bytes copied, \
0.000291134 s, 343 kB/s<br>8192+0 records in<br>8192+0 records out<br>8388608 bytes \
(8.4 MB, 8.0 MiB) copied, 0.0447136 s, 188 MB/s<br>done 0<br>tee \
0<br></div><div><br></div><div>both prior pipeline elements have exit code zero and \
the first stage processed all of the data</div><div><br></div><div>The POSIX spec for \
tee reads:</div><div><a \
href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html" \
target="_blank">https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html</a> \
<br><h4 class="gmail-m_5126291428043663572gmail-mansect" \
style="color:rgb(0,102,0);font-style:italic;font-size:12pt">CONSEQUENCES OF \
ERRORS</h4><blockquote \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><p>If \
a write to any successfully opened  <i>file</i>  operand fails, writes to other \
successfully opened  <i>file</i>  operands and standard output shall continue, but \
the exit status shall be non-zero. Otherwise, the default actions specified in  <a \
href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html#tag_17_04" \
style="color:rgb(102,102,255)" target="_blank"><i>Utility Description \
Defaults</i></a>  apply.</p></blockquote>But this case deals with a failure to write \
to stdout, not a failure to write to a <i>file</i> \
operand.</div><div><br></div><div>Certainly, with this behaviour, busybox tee does \
not comply with GNU tee as it appears to intend, so I suggest that the line  <span \
class="gmail-m_5126291428043663572gmail-n">signal</span><span \
class="gmail-m_5126291428043663572gmail-p">(</span><span \
class="gmail-m_5126291428043663572gmail-n">SIGPIPE</span><span \
class="gmail-m_5126291428043663572gmail-p">,</span> <span \
class="gmail-m_5126291428043663572gmail-n">SIG_IGN</span><span \
class="gmail-m_5126291428043663572gmail-p">) be removed.</span></div><div><span \
class="gmail-m_5126291428043663572gmail-p"><br></span></div><div><span \
class="gmail-m_5126291428043663572gmail-p">To meet the probable intent, the signal \
should probably be ignored while writing to file operands (in case they turn out to \
be pipes) and enabled each time when writing to \
stdout.</span></div><div><br></div><div>Sam  </div></div> </blockquote></div>



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic