bug-gawk
[Top][All Lists]
Advanced

[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: Fri, 10 Mar 2017 10:23:09 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

Thanks for these bug reports. I think the basic problem is that
we ignore SIGPIPE and rely upon detecting write errors.
When print is called, it checks the return code from fwrite
and exits on error (in io.c:efwrite).

When fflush is called, I think fwrite never returns an error
due to stdio buffering. The fwrite call succeeds, and then
the subsequent call to fflush actually triggers the write system
call that returns the error. The fflush() returns an error status
in this case:

bash-4.2$ yes | ./gawk '{print; if ((rc = fflush("/dev/stdout")) != 0) {printf 
"fflush failed with status %s\n", rc > "/dev/stderr"; exit}}' | head
y
y
y
y
y
y
y
y
y
y
fflush failed with status -1

I guess the fix is probably to add some logic to issue a fatal error
when fflush fails, unless the output file is registered as NONFATAL.
The only question is whether this might break existing code.

A possible patch to the master branch is attached. This will NOT apply
against 4.1.x. Sorry.

Regards,
Andy

Attachment: fflush_error.patch
Description: Text document


reply via email to

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