[Top][All Lists]

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

Re: [bug-gawk] Behavior of fflush with SIGPIPE on stdout [PATCH]

From: Andrew J. Schorr
Subject: Re: [bug-gawk] Behavior of fflush with SIGPIPE on stdout [PATCH]
Date: Sat, 25 Mar 2017 10:39:05 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Mar 25, 2017 at 03:30:35PM +0100, FERRIEUX Alexandre - IMT/OLN wrote:
> Yes, that may happen if the output from "cat" fits within a pipe
> buffer: a single write() completes without blocking ; then "head"
> exits after reading part or all of it (depending on stdin buffer
> settings), but it's way too late for any feedback like sending a
> SIGPIPE, since nobody's writing at the time.
> Use the command "yes" instead of "cat /etc/services". It never stops.

Fair point. That's exactly what's happening. The /etc/services file on Cygwin
isn't large enough. :-)

> Nope, I don't have any Windows. But I tend to hope that the
> development of such a venerable pillar of the unix universe as Awk,
> will not take Windows (even Cygwin) as a reference. Windows may not
> get what a file descriptor or exit status means, we still need gawk
> to get it right on Unix.

It's actually 141 on Cygwin also.

> You may wonder why the detailed exit status matters.
> First, of course, a script may inspect $? and act accordingly.
> But a much more prevalent use is the following:
>       - I'm debugging a big contraption made of dozens of pipe-connected 
> processes (not necessarily written by me)
>       - half of them are Awk processes
>       - At some point, things go awry, some of the processes exiting 
> prematurely, and the others following by starvation.
> In this situation, I need to understand why each one died: EOF, SIGPIPE, or 
> intentional exit ?
> To this effect, "strace -f" gives all the answers in one single
> command. This is true of all unix filters that use the default
> SIGPIPE behavior (without even setting a handler): cut, sed, grep,
> old awk. If this stops being true for shiny gawk for no better
> reason than "Windows people don't need it", that's tough.

I'm a bit confused by this. Even with the newly patched version of gawk that
exits with status 0 when EPIPE occurs, strace shows this:

bash-4.2$ (strace ./gawk 1 /etc/services | head -1) 2>&1 | tail
fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
read(3, " 79/tcp\nfinger                  "..., 4096) = 4096
write(1, "rtmp                     1/ddp\nt"..., 4096) = 4096
rtmp                     1/ddp
read(3, "         141/tcp\nemfis-cntl     "..., 4096) = 4096
write(1, " 79/tcp\nfinger                  "..., 4096) = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=372, si_uid=300} ---
exit_group(0)                           = ?
+++ exited with 0 +++

So the SIGPIPE should be visible in the strace output, regardless of the fact
that gawk is ignoring it, and regardless of the exit status.  I agree that
exiting with 0 success status is a bit deceptive, but I'm less convinced that
we need to mirror the untrapped SIGPIPE 141 exit status...


reply via email to

[Prev in Thread] Current Thread [Next in Thread]