From 438e6e6e6deb8f4831e84ffd17205dc14d3a2ebb Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 10 Feb 2022 09:25:18 +0200 Subject: Small formatting fix. --- ChangeLog | 4 ++++ builtin.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6f99be92..65c902a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2022-02-10 Arnold D. Robbins + + * builtin.c (sanitize_exit_status): Fix formatting. + 2022-02-07 Arnold D. Robbins Continue fixing indirect calls of builtins. diff --git a/builtin.c b/builtin.c index 060b2f28..2a1869e6 100644 --- a/builtin.c +++ b/builtin.c @@ -4399,7 +4399,8 @@ mbc_char_count(const char *ptr, size_t numbytes) /* sanitize_exit_status --- convert a 16 bit Unix exit status into something reasonable */ -int sanitize_exit_status(int status) +int +sanitize_exit_status(int status) { int ret = 0; -- cgit v1.2.3 From 938afb4d7acb9974d5789dfe4e322c0ccce0541e Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Thu, 10 Feb 2022 15:00:24 -0500 Subject: Fix bug in exit status returned by close for a previously exited process. --- ChangeLog | 10 ++++++++++ io.c | 4 ++-- pc/ChangeLog | 4 ++++ pc/Makefile.tst | 8 +++++++- test/ChangeLog | 5 +++++ test/Makefile.am | 5 ++++- test/Makefile.in | 10 +++++++++- test/Maketests | 5 +++++ test/close_status.awk | 20 ++++++++++++++++++++ test/close_status.ok | 6 ++++++ 10 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 test/close_status.awk create mode 100644 test/close_status.ok diff --git a/ChangeLog b/ChangeLog index 65c902a8..ce603e94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2022-12-10 Andrew J. Schorr + + * io.c (wait_any): When saving a saved exit status returned by + _cwait or waitpid or wait in struct redirect's status field, we + should actually save the valued returned by sanitize_exit_status + instead of the raw status. This fixes a bug whereby a saved status + for a previously exited process was being returned by gawk_pclose + without first being sanitized. Thanks to Jakub Martisko + for reporting the bug. + 2022-02-10 Arnold D. Robbins * builtin.c (sanitize_exit_status): Fix formatting. diff --git a/io.c b/io.c index 1d440c1e..07d83689 100644 --- a/io.c +++ b/io.c @@ -2599,7 +2599,7 @@ wait_any(int interesting) /* pid of interest, if any */ for (redp = red_head; redp != NULL; redp = redp->next) if (interesting == redp->pid) { redp->pid = -1; - redp->status = status; + redp->status = sanitize_exit_status(status); break; } } @@ -2629,7 +2629,7 @@ wait_any(int interesting) /* pid of interest, if any */ for (redp = red_head; redp != NULL; redp = redp->next) if (pid == redp->pid) { redp->pid = -1; - redp->status = status; + redp->status = sanitize_exit_status(status); break; } } diff --git a/pc/ChangeLog b/pc/ChangeLog index e75df278..c5043baf 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,7 @@ +2022-12-10 Andrew J. Schorr + + * Makefile.tst: Regenerated. + 2022-02-09 Arnold D. Robbins * Makefile.tst: Regenerated. diff --git a/pc/Makefile.tst b/pc/Makefile.tst index f25e887b..4b3fb0a5 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -147,7 +147,8 @@ BASIC_TESTS = \ aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 aryprm8 aryprm9 \ arysubnm aryunasgn asgext awkpath assignnumfield assignnumfield2 \ back89 backgsub badassign1 badbuild callparam childin clobber \ - closebad clsflnam compare compare2 concat1 concat2 concat3 concat4 \ + closebad close_status clsflnam compare compare2 concat1 concat2 \ + concat3 concat4 \ concat5 convfmt datanonl defref delargv delarpm2 delarprm delfunc \ dfacheck2 dfamb1 dfastress dynlj escapebrace eofsplit eofsrc1 \ exit2 exitval1 exitval2 exitval3 fcall_exit fcall_exit2 fldchg \ @@ -1430,6 +1431,11 @@ closebad: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +close_status: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + clsflnam: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/ChangeLog b/test/ChangeLog index c45b2f43..ddae26ea 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2022-02-10 Andrew J. Schorr + + * Makefile.am (EXTRA_DIST): close_status, new test. + * close_status.awk, close_status.ok: New files. + 2022-02-09 Arnold D. Robbins * Makefile.am (EXTRA_DIST): indirectbuiltin2, new test. diff --git a/test/Makefile.am b/test/Makefile.am index 424aaa82..96dd3027 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -189,6 +189,8 @@ EXTRA_DIST = \ clos1way6.ok \ closebad.awk \ closebad.ok \ + close_status.awk \ + close_status.ok \ clsflnam.awk \ clsflnam.in \ clsflnam.ok \ @@ -1402,7 +1404,8 @@ BASIC_TESTS = \ aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 aryprm8 aryprm9 \ arysubnm aryunasgn asgext awkpath assignnumfield assignnumfield2 \ back89 backgsub badassign1 badbuild callparam childin clobber \ - closebad clsflnam compare compare2 concat1 concat2 concat3 concat4 \ + closebad close_status clsflnam compare compare2 concat1 concat2 \ + concat3 concat4 \ concat5 convfmt datanonl defref delargv delarpm2 delarprm delfunc \ dfacheck2 dfamb1 dfastress dynlj escapebrace eofsplit eofsrc1 \ exit2 exitval1 exitval2 exitval3 fcall_exit fcall_exit2 fldchg \ diff --git a/test/Makefile.in b/test/Makefile.in index 82b60902..94699c32 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -455,6 +455,8 @@ EXTRA_DIST = \ clos1way6.ok \ closebad.awk \ closebad.ok \ + close_status.awk \ + close_status.ok \ clsflnam.awk \ clsflnam.in \ clsflnam.ok \ @@ -1668,7 +1670,8 @@ BASIC_TESTS = \ aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 aryprm8 aryprm9 \ arysubnm aryunasgn asgext awkpath assignnumfield assignnumfield2 \ back89 backgsub badassign1 badbuild callparam childin clobber \ - closebad clsflnam compare compare2 concat1 concat2 concat3 concat4 \ + closebad close_status clsflnam compare compare2 concat1 concat2 \ + concat3 concat4 \ concat5 convfmt datanonl defref delargv delarpm2 delarprm delfunc \ dfacheck2 dfamb1 dfastress dynlj escapebrace eofsplit eofsrc1 \ exit2 exitval1 exitval2 exitval3 fcall_exit fcall_exit2 fldchg \ @@ -3134,6 +3137,11 @@ closebad: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +close_status: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + clsflnam: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 4c4cfa62..26831128 100644 --- a/test/Maketests +++ b/test/Maketests @@ -185,6 +185,11 @@ closebad: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +close_status: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + clsflnam: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/close_status.awk b/test/close_status.awk new file mode 100644 index 00000000..12b48d63 --- /dev/null +++ b/test/close_status.awk @@ -0,0 +1,20 @@ +BEGIN { + exit9 = "echo red; exit 9" + while ((exit9 | getline x) > 0) + print x + printf "close(%s) returned %s\n", exit9, close(exit9) + + # run it again, but don't reap the exit status + while ((exit9 | getline x) > 0) + print x + + exit0 = "echo blue; exit 0" + while ((exit0 | getline x) > 0) + print x + # reap status out of order + printf "close(%s) returned %s\n", exit0, close(exit0) + + # check that we got the correct status from the previously + # exited process + printf "close(%s) returned %s\n", exit9, close(exit9) +} diff --git a/test/close_status.ok b/test/close_status.ok new file mode 100644 index 00000000..fbdebeb0 --- /dev/null +++ b/test/close_status.ok @@ -0,0 +1,6 @@ +red +close(echo red; exit 9) returned 9 +red +blue +close(echo blue; exit 0) returned 0 +close(echo red; exit 9) returned 9 -- cgit v1.2.3