[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Undetected fatal errors from redirected print
From: |
Andrew J. Schorr |
Subject: |
Re: Undetected fatal errors from redirected print |
Date: |
Wed, 24 Nov 2021 08:41:46 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Tue, Nov 23, 2021 at 08:42:49PM -0500, Miguel Pineiro Jr. wrote:
> On Tue, Nov 23, 2021, at 6:24 PM, Andrew J. Schorr wrote:
> > The fclose has to do an implicit fflush, of course, before closing the
> > file. Are
> > you suggesting we should call fflush prior to fclose and then issue an
> > error if
> > fflush fails (but not if fclose fails)?
>
> Yes, to distinguish a fatal error in the print statement's output from
> subsequent, unrelated stream closing errors. Perhaps something like do_fflush
> (which understands when a redirection has been declared nonfatal).
This does not feel like an important distinction to me. I will note
that both mawk and nawk throw an error in this scenario:
sh-5.1$ strace -fo /tmp/trace.txt -P /tmp/answer.txt -e fault=write gawk 'BEGIN
{print "42" > "/tmp/answer.txt"}'
sh-5.1$ strace -fo /tmp/trace.txt -P /tmp/answer.txt -e fault=write mawk 'BEGIN
{print "42" > "/tmp/answer.txt"}'
mawk: close failed on file /tmp/answer.txt (Function not implemented)
sh-5.1$ strace -fo /tmp/trace.txt -P /tmp/answer.txt -e fault=write nawk 'BEGIN
{print "42" > "/tmp/answer.txt"}'
nawk: write error on /tmp/answer.txt
source line number 1
It looks like nawk is flushing after each write, which seems fairly
suboptimal from a performance perspective:
sh-5.1$ strace -fo /tmp/trace.txt -P /tmp/answer.txt -e fault=write nawk 'BEGIN
{f = "/tmp/answer.txt"; for (i = 1; i < 10; i++) {print i; print i > f}}'
1
nawk: write error on /tmp/answer.txt
source line number 1
compared to:
sh-5.1$ strace -fo /tmp/trace.txt -P /tmp/answer.txt -e fault=write gawk 'BEGIN
{f = "/tmp/answer.txt"; for (i = 1; i < 10; i++) {print i; print i > f}}'
1
2
3
4
5
6
7
8
9
sh-5.1$ strace -fo /tmp/trace.txt -P /tmp/answer.txt -e fault=write mawk 'BEGIN
{f = "/tmp/answer.txt"; for (i = 1; i < 10; i++) {print i; print i > f}}'
1
2
3
4
5
6
7
8
9
mawk: close failed on file /tmp/answer.txt (Function not implemented)
So do you object to the fact that mawk labels this as a close error
instead of a write error? The mawk behavior is fairly similar to the
gawk --lint behavior:
sh-5.1$ strace -fo /tmp/trace.txt -P /tmp/answer.txt -e fault=write gawk --lint
'BEGIN {f = "/tmp/answer.txt"; for (i = 1; i < 10; i++) {print i; print i > f}}'
1
2
3
4
5
6
7
8
9
gawk: warning: failure status (-1) on file close of `/tmp/answer.txt': Function
not implemented
gawk: warning: no explicit close of file `/tmp/answer.txt' provided
Regards,
Andy
- Undetected fatal errors from redirected print, Miguel Pineiro Jr., 2021/11/22
- Re: Undetected fatal errors from redirected print, Andrew J. Schorr, 2021/11/22
- Re: Undetected fatal errors from redirected print, arnold, 2021/11/23
- Re: Undetected fatal errors from redirected print, Miguel Pineiro Jr., 2021/11/23
- Re: Undetected fatal errors from redirected print, Andrew J. Schorr, 2021/11/23
- Re: Undetected fatal errors from redirected print, Miguel Pineiro Jr., 2021/11/23
- Re: Undetected fatal errors from redirected print, Andrew J. Schorr, 2021/11/23
- Re: Undetected fatal errors from redirected print, Miguel Pineiro Jr., 2021/11/23
- Re: Undetected fatal errors from redirected print,
Andrew J. Schorr <=
- Re: Undetected fatal errors from redirected print, arnold, 2021/11/25
- Re: Undetected fatal errors from redirected print, Miguel Pineiro Jr., 2021/11/26
- Re: Undetected fatal errors from redirected print, arnold, 2021/11/26
- Re: Undetected fatal errors from redirected print, Miguel Pineiro Jr., 2021/11/26
- Re: Undetected fatal errors from redirected print, Andrew J. Schorr, 2021/11/26
- Re: Undetected fatal errors from redirected print, Miguel Pineiro Jr., 2021/11/27
- Re: Undetected fatal errors from redirected print, Andrew J. Schorr, 2021/11/27
- Re: Undetected fatal errors from redirected print, Andrew J. Schorr, 2021/11/29
- Re: Undetected fatal errors from redirected print, arnold, 2021/11/30
- Re: Undetected fatal errors from redirected print, Andrew J. Schorr, 2021/11/30