aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2022-02-11 11:47:47 +0200
committerArnold D. Robbins <arnold@skeeve.com>2022-02-11 11:47:47 +0200
commit255f50dd5427a17e5277a30d98b0a1c5eaec6001 (patch)
tree95a94b431c4a0fc7bd8aff53cff862b628fc6ca8
parent9b8d1fd59b0b4119097bb9943620804c12d1bf0a (diff)
parent938afb4d7acb9974d5789dfe4e322c0ccce0541e (diff)
downloadegawk-255f50dd5427a17e5277a30d98b0a1c5eaec6001.tar.gz
egawk-255f50dd5427a17e5277a30d98b0a1c5eaec6001.tar.bz2
egawk-255f50dd5427a17e5277a30d98b0a1c5eaec6001.zip
Merge branch 'gawk-5.1-stable'
-rw-r--r--ChangeLog14
-rw-r--r--builtin.c3
-rw-r--r--io.c4
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst8
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am5
-rw-r--r--test/Makefile.in10
-rw-r--r--test/Maketests5
-rw-r--r--test/close_status.awk20
-rw-r--r--test/close_status.ok6
11 files changed, 78 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 6de016d7..67a0298c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2022-12-10 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * 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
+ <jamartis@redhat.com> for reporting the bug.
+
+2022-02-10 Arnold D. Robbins <arnold@skeeve.com>
+
+ * builtin.c (sanitize_exit_status): Fix formatting.
+
2022-02-07 Arnold D. Robbins <arnold@skeeve.com>
Continue fixing indirect calls of builtins.
diff --git a/builtin.c b/builtin.c
index 2e772e87..1e71c0e8 100644
--- a/builtin.c
+++ b/builtin.c
@@ -4402,7 +4402,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;
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 a3e90ec8..cc48e0c2 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2022-12-10 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * Makefile.tst: Regenerated.
+
2022-02-09 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Regenerated.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 68e22751..f49d66bd 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 \
@@ -1431,6 +1432,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 0166997c..6d1758b5 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2022-02-10 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * Makefile.am (EXTRA_DIST): close_status, new test.
+ * close_status.awk, close_status.ok: New files.
+
2022-02-10 Arnold D. Robbins <arnold@skeeve.com>
* nsidentifier.ok: Update after code changes.
diff --git a/test/Makefile.am b/test/Makefile.am
index f76f5d48..1a22118b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -191,6 +191,8 @@ EXTRA_DIST = \
clos1way6.ok \
closebad.awk \
closebad.ok \
+ close_status.awk \
+ close_status.ok \
clsflnam.awk \
clsflnam.in \
clsflnam.ok \
@@ -1404,7 +1406,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 f0e2894a..be8e0345 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -457,6 +457,8 @@ EXTRA_DIST = \
clos1way6.ok \
closebad.awk \
closebad.ok \
+ close_status.awk \
+ close_status.ok \
clsflnam.awk \
clsflnam.in \
clsflnam.ok \
@@ -1670,7 +1672,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 \
@@ -3137,6 +3140,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 923e1f78..10ef252f 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