tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: why complain about a broken pipe?

On Wed, 8 Feb 2012 01:44:51 -0500 (EST)
Mouse <mouse%Rodents-Montreal.ORG@localhost> wrote:

> > I posted my original query because I object to pax (and xargs)
> > complaining about EPIPE.  I don't see the need.  The script can't
> > capture it,
> Actually, scripts _can_ capture it.  stderr can be redirected.

Oh, yes, I know.  To split the hair ever so finely, "it" in that
sentence is meant to refer to EPIPE.  It doesn't show up in the 
shell's $? variable or similar, and can't be acted on

> xargs is, if you will, acting as a
> (severely special-case) shell in that it's running other
> user-specified processes; as such, it's well within its bailiwick to
> report on abnormal terminations.  

Oh, no.  xargs is no shell at all!  It's a mere re-arranger made
necessary by mistaken choices, an ugly elbow-joint in the pipe.  

        $ find /usr | xargs ls -F 

could as well be expressed as 

        $ ls -F $(find /usr)

or even 

        $ find /usr | ls -F 

but for accidents of history.  As such, xargs has no more right to talk
to the user than the "|" character, and as much duty to report the exit

> Well, if you don't have SIGPIPE ignored, caught, or blocked, you
> don't last long enough to even _get_ EPIPE

Ah.  I would have stumbled on that eventually, but I appreciate the
education.  You're quite right, of course: pax.c ignores SIGPIPE around
line 430.  

It needs to because "pax -w" writes an archive to standard output by
default.  Connect it to ssh to copy files across a network.  Which, I
admit, is kinda important to get right.  

$ pax -w * | hexdump -C | head -1
00000000  1b 5b 3f 31 3b 32 63 1b  5b 3f 31 3b 32 63 1b 5b  |.[?1;2c.[?
pax: Failed write to archive volume: 1 (Broken pipe)

ATTENTION! pax archive volume change required.
Ready for archive volume: 2
Input archive name or "." to quit pax.
Archive name > ^C
pax: Signal caught, cleaning up.

Typing "." yields a list of files not processed, something that would
be a lot harder to do without ignoring SIGPIPE.  ;-)   And, as we'll
hear a lot in the coming months here in the US, I approve of this
message.  About not being able to write the archive volume, that is.  

The table of contents is another matter....



Home | Main Index | Thread Index | Old Index