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


From: david kerns
Subject: Re: [bug-gawk] Behavior of fflush with SIGPIPE on stdout
Date: Tue, 7 Mar 2017 09:25:44 -0700

as another data point, I think this related behaviour is also incorrect:

$ mknod /tmp/pipe p
$ yes | awk '{print > "/tmp/pipe";fflush("/tmp/pipe")}' &
$ head -3 /tmp/pipe
y
y
y
$ head -3 /tmp/pipe
y
y
y

the second head should have blocked for a writer, since the close of the first head should have terminated the awk
(which is what you get w/out the flush)

$ yes | awk '{print > "/tmp/pipe"}' &                  
[1]     27640
$ head -3 /tmp/pipe                   
y
y
y
$ awk: cmd. line:1: (FILENAME=- FNR=4097) fatal: print to "/tmp/pipe" failed (Broken pipe)
yes: standard output: Connection reset by peer
yes: write error

[1] +  Done(2)                    yes | awk '{print > "/tmp/pipe"}' &



On Tue, Mar 7, 2017 at 3:42 AM, <address@hidden> wrote:
Hi,

After a recent OS upgrade on the only machine where I do heavy awk work, I got caught by a regression dated 2013 in gawk, namely the one about "ignored SIGPIPE".

Basically, what happens is that the ages-old unix idiom

        infinite-data-source | filter | head

fails if "filter" is a post-2013 gawk using explicit fflush().

Example:

        yes | awk '{print;fflush(stdout)}' | head

Of course this is a cooked example, but I guess you can imagine the real-life situations where explicit fflush() is needed, with appropriate task-dependent granularity, for performance and interactivity.


Looking at the comments in main.c, I do not see whether this regression was considered or not.
It rather looks like the idea of "writing to a pipe" was generally thought about in the context of additional fds ("print ... | cmd"), but that the simple, obvious case of

        - gawk used as a unix filter
        - stdout is a pipe

was overlooked.

I assume this is just a shallow search on my part; thanks in advance for giving pointers to the relevant discussion and release notes announcing this regression, and the idiomatic ways to avoid it.

-Alex

PS: Note that crude versions of awk like "mawk" don't have the issue, but I need gawk for the obvious reasons.


_________________________________________________________________________________________________________________________

Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.




reply via email to

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