aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-04-04 23:11:19 +0300
committerArnold D. Robbins <arnold@skeeve.com>2016-04-04 23:11:19 +0300
commit1b5d1b8870cb0ac1c4b99f6cf67e3277427df864 (patch)
tree910c37dfb0821cc23de5402c44e4603d2e734721
parentfae30f292fc0e2e67de188f8129d043f9909bd0b (diff)
downloadegawk-1b5d1b8870cb0ac1c4b99f6cf67e3277427df864.tar.gz
egawk-1b5d1b8870cb0ac1c4b99f6cf67e3277427df864.tar.bz2
egawk-1b5d1b8870cb0ac1c4b99f6cf67e3277427df864.zip
Add warning for fflush of closed write end on 2-way pipe.
-rw-r--r--ChangeLog6
-rw-r--r--builtin.c3
-rw-r--r--io.c3
-rw-r--r--test/ChangeLog2
-rw-r--r--test/clos1way2.awk1
-rw-r--r--test/clos1way2.ok3
6 files changed, 16 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7ba50e8c..d34c136e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-04-04 Arnold D. Robbins <arnold@skeeve.com>
+
+ * builtin.c (do_fflush): Add warning for flush to two-way
+ pipe where write end was closed.
+ * io.c (flush_io): Add some braces for the for loop.
+
2016-04-02 Arnold D. Robbins <arnold@skeeve.com>
* builtin.c (do_printf): If the redirection is two way but the
diff --git a/builtin.c b/builtin.c
index c4d3d3a1..a1c09d5a 100644
--- a/builtin.c
+++ b/builtin.c
@@ -237,6 +237,9 @@ do_fflush(int nargs)
fp = rp->output.fp;
if (fp != NULL)
status = rp->output.gawk_fflush(fp, rp->output.opaque);
+ else if ((rp->flag & RED_TWOWAY) != 0)
+ warning(_("fflush: cannot flush: two-way pipe `%s' has closed write end"),
+ file);
} else if ((fp = stdfile(tmp->stptr, tmp->stlen)) != NULL) {
status = fflush(fp);
} else {
diff --git a/io.c b/io.c
index de753973..fe1261aa 100644
--- a/io.c
+++ b/io.c
@@ -1328,7 +1328,7 @@ flush_io()
warning(_("error writing standard error (%s)"), strerror(errno));
status++;
}
- for (rp = red_head; rp != NULL; rp = rp->next)
+ for (rp = red_head; rp != NULL; rp = rp->next) {
/* flush both files and pipes, what the heck */
if ((rp->flag & RED_WRITE) != 0 && rp->output.fp != NULL) {
if (rp->output.gawk_fflush(rp->output.fp, rp->output.opaque)) {
@@ -1344,6 +1344,7 @@ flush_io()
status++;
}
}
+ }
if (status != 0)
status = -1; /* canonicalize it */
return status;
diff --git a/test/ChangeLog b/test/ChangeLog
index 80b2c233..2867f6cb 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -5,6 +5,8 @@
* clos1way2.awk, clos1way2.in, clos1way2.ok, clos1way3.awk,
clos1way3.ok, clos1way4.awk, clos1way4.ok, clos1way5.awk,
clos1way5.ok: New files.
+ * clos1way2.awk: Add call to fflush() to test it too.
+ * clos1way2.ok: Updated after code change.
2016-02-18 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/test/clos1way2.awk b/test/clos1way2.awk
index 7dab6a67..5794bec5 100644
--- a/test/clos1way2.awk
+++ b/test/clos1way2.awk
@@ -1,5 +1,6 @@
{
cmd = "cat - 1>&2; sleep 2"
print |& cmd; close(cmd, "to")
+ fflush(cmd)
print |& cmd; print ERRNO
}
diff --git a/test/clos1way2.ok b/test/clos1way2.ok
index 22bd3e17..063c4213 100644
--- a/test/clos1way2.ok
+++ b/test/clos1way2.ok
@@ -1,3 +1,4 @@
-gawk: clos1way2.awk:4: (FILENAME=- FNR=1) fatal: print: attempt to write to closed write end of two-way pipe
+gawk: clos1way2.awk:4: (FILENAME=- FNR=1) warning: fflush: cannot flush: two-way pipe `cat - 1>&2; sleep 2' has closed write end
+gawk: clos1way2.awk:5: (FILENAME=- FNR=1) fatal: print: attempt to write to closed write end of two-way pipe
test
CODE: 2