bug-gawk
[Top][All Lists]
Advanced

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

Re: [BUG]? Strange return values of close()


From: Andrew J. Schorr
Subject: Re: [BUG]? Strange return values of close()
Date: Wed, 9 Feb 2022 16:01:28 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

Thanks for the bug report. The problem is that the exit status of a previously
reaped process is not being handled properly. The attached patch seems to fix
the issue for me, but I'm not able to test the Mingw32 piece of it. We should
probably add a test case and check that it works on all platforms.

Regards,
Andy

On Wed, Feb 09, 2022 at 03:44:03PM +0100, Jakub Martisko wrote:
> Hello,
> 
> there seems to be some strange behaviour with the close (reproducer is
> attached in case the formatting gets messed). Is the RC echo=2304 expected
> or is this a bug? I've tested the same thing with the gawk-4.0.2 (i.e.
> before the change described in) and it returns 2304 in all four cases.
> 
> Thanks,
> Jakub
> 
> [1]:
> https://www.gnu.org/software/gawk/manual/html_node/Close-Files-And-Pipes.html#FOOT29
> 
> $ ls
> gwk_prog
> $ gawk -f ./gwk_prog
> RC Empty=9 #this is the expected value based on unzip's return values
> RC echo=9
> $ unzip -o ./test.zip 2>/dev/null; echo $?
> 9
> 
> $ touch ./test.zip
> 
> $ ls
> 
> gwk_prog  test.zip
> $ gawk -f ./gwk_prog
> RC Empty=9
> RC echo=2304 # this is 256*9 btw
> $ unzip -o ./test.zip 2>/dev/null; echo $?
> 
> Archive:  ./test.zip
> 9
> 
> $ cat gwk_prog
> #!/usr/bin/gawk -f
> 
> BEGIN{
> rc=0;
> 
> extract_file="unzip -o ./test.zip 2>/dev/null";
> 
> #Just an empty cycle - returns 9 as expected
> while (extract_file|getline){
> continue;
> }
> rc=close(extract_file);
> print "RC Empty="rc;
> 
> 
> #Non empty cycle - extract_file should return 9
> while (extract_file|getline){
> cmd="echo"
> cmd|getline
> close(cmd)
> }
> rc=close(extract_file);
> print "RC echo="rc;
> }

> 
> #!/usr/bin/gawk -f
> 
> BEGIN{
> rc=0;
> 
> extract_file="unzip -o ./test.zip 2>/dev/null";
> 
> #Just an empty cycle - returns 9 as expected
> while (extract_file|getline){
> continue;
> }
> rc=close(extract_file);
> print "RC Empty="rc;
> 
> 
> #Non empty cycle - extract_file should return 9
> while (extract_file|getline){
>       cmd="echo"
>       cmd|getline
>       close(cmd)
> }
> rc=close(extract_file);
> print "RC echo="rc;
> 
> }

Attachment: status.patch
Description: Text document


reply via email to

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